Why list.sort() don't return the list reference instead of None?

Lawrence Oluyede raims at dot.com
Mon May 8 03:09:44 EDT 2006


"ankyhe at gmail.com" <ankyhe at gmail.com> writes:

> However, I wonder why L.sort() don't return the reference L, the
> performance of return L and None may be the same. 

It's not "the same". sort() does not return anything.

> Why?

I've just explained to you and so the others: by default operations on mutable
objects are in place.

s = "abc"
s.upper()

does return another string. String are immutable references.

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier



More information about the Python-list mailing list