Why return None?

Martin DeMello martindemello at yahoo.com
Wed Aug 25 08:37:46 EDT 2004


Dan Sommers <me at privacy.net> wrote:
 
> If list.sort returned the sorted list, how many lists would there be
> after this code executed?
> 
>     original_list = a_function_that_returns_a_list( )
>     sorted_list = original_list.sort( )

One - sorted_list would be a reference to the (now sorted) original
list. The newbie problem could be solved by having <verb> and <verbed>
versions of each destructive method - i.e. list.sort() to sort the list
in-place and return it, and list.sorted() to return a new, sorted list,
and experienced users could chain methods and all that other good stuff.

martin



More information about the Python-list mailing list