Why return None?

Alex Martelli aleaxit at yahoo.com
Thu Aug 26 09:40:40 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> aleaxit at yahoo.com (Alex Martelli) writes:
> > There should be one-- and preferably only one --obvious way to do it.
> > 
> > Not leaving stylistic choice (which would lead to more than one obvious
> > way to do it) is quite consonant with the Zen of Python.
> 
> Well, what you're left with is that doing it the one obvious way
> doesn't work, and you have to do it in some contorted way instead.

If somelist.sort() returned the list there could not possibly be one
obvious way to do it, since both

print somelist.sort()

and

somelist.sort()
print somelist

would be ways to do it, both pretty obvious to different people.  [[The
introduction of 'sorted' will muddy 'obviousness' for some, but IMHO it
just changes what the one obvious way is: if you do want an inplace
sort, then somelist.sort(), otherwise then sorted(somelist) when you do
not want to alter somelist in place.]]


Alex



More information about the Python-list mailing list