[Tutor] python coding problem

Ben Finney ben+python at benfinney.id.au
Mon Sep 26 16:19:54 EDT 2016


Alex Hall <ahall at autodist.com> writes:

> On Mon, Sep 26, 2016 at 11:35 AM, Richard Koeman <rkoeman at smcdsb.on.ca>
> wrote:
>
> > def maximum(n1, n2):
> >   print "the first number is" ,n1
> >   print "the second number is", n2
> >   if n1 > n2:
> >     return
>
> Using the 'return' keyword will return whatever follows it (nothing, in
> this case).

Not nothing; the ‘return‛ statement will *always* return an object.

‘return’ without an argument is a special case. It returns the ‘None’
object.

> However, it also stops your function from doing anything else.
> Think of it as telling the function "stop here, and do nothing else. Just
> quit now."

Rather, the ‘return’ statement tells the interpreter “return from where
you called this function, bringing with you this specified object”. In
this case, it brings the ‘None’ object.

It does indeed cease executing the function, but that's because it
continues elsewhere (back at the site where the function was called).

-- 
 \             “No smoothen the lion.” —lion cage, zoo, Czech Republic |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Tutor mailing list