[Tutor] If a method has no return type?

Timo timomlists at gmail.com
Thu Feb 7 11:25:13 CET 2013


Op 07-02-13 10:09, Sunil Tech schreef:
> Thank you Wesley, Kal & tutor
In the future, the Python interpreter comes in handy for quick checks.

 >>> def spam():
...   pass
...
 >>> s = spam()
 >>> s, repr(s), type(s)
(None, 'None', <type 'NoneType'>)

Timo

>
>
> On Thu, Feb 7, 2013 at 12:07 PM, Kal Sze <swordangel at gmail.com 
> <mailto:swordangel at gmail.com>> wrote:
>
>     Dear Sunil,
>
>     No method or function in Python has a *static* return type. That's
>     because Python is by nature a dynamic language, with duck typing and
>     dynamic dispatch. In fact, any method or function may well return any
>     of a number of different types:
>
>         def crazy_function(return_int)
>             if return_int:
>                 return 1
>             else:
>                 return 'foo'
>
>     It's probably bad design, but there is nothing in the Python grammar
>     and semantics that stops you from doing that.
>
>     So your question is better phrased as: if I don't explicitly return
>     anything, what is returned?
>
>     The answer to that would be: the None object
>
>     Cheers,
>     Kal
>
>     On 7 February 2013 14:09, Sunil Tech <sunil.techspk at gmail.com
>     <mailto:sunil.techspk at gmail.com>> wrote:
>     > If a method has no return type?
>     > what will it return?
>     >
>     > _______________________________________________
>     > Tutor maillist  - Tutor at python.org <mailto:Tutor at python.org>
>     > To unsubscribe or change subscription options:
>     > http://mail.python.org/mailman/listinfo/tutor
>     >
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list