Function passed as an argument returns none

Shiva shivaji_tn at yahoo.com
Thu Oct 2 04:46:13 EDT 2014


Hi All,

Thank you everyone. This is fantastic - I post a query and go to sleep and
by the time I get up there is already a nice little thread of discussion
going on.....

By the way, I sorted it with all your suggestions.

def donuts(count):
  if count <= 9:     #This had to be 9 instead of 5 as per the question req.
    return 'Number of donuts: {0}'.format(count)
  else:
    return 'Number of donuts: many'

So to summarise what I learnt:

* Just 'return' returns None - it is not related to what you print inside
the function.If you want something specific out of a function return
something specific.

* return 'Number of donuts: ',count    returns a tuple like:
('Number of donuts: ',9)

* To just print the string without returning it as tuple , use string
formatting.

Thanks again,
Shiva




More information about the Python-list mailing list