[Tutor] Puzzled by print lst.sort()

Dick Moores rdm at rcblue.com
Sat Sep 30 12:09:50 CEST 2006


 >>> lst = [5,3,7,6,2]
 >>> lst.sort()
 >>> lst
[2, 3, 5, 6, 7]
 >>> lst = [5,3,7,6,2]
 >>> print lst.sort()
None
 >>> lst
[2, 3, 5, 6, 7]

I'm wondering why "print lst.sort()" doesn't print the newly sorted 
list, but instead prints "None". In fact, the sorting has taken place 
because of "print lst.sort()". Is this behavior a Good Thing in Python?

Dick



More information about the Tutor mailing list