业精于勤,荒于嬉;行成于思,毁于随。
Because the type returned by the sort method of List is <type 'NoneType'>, your print here is not list1.
>>> list1=[3,2,5,6,1] >>> print type(list1.sort()) <type 'NoneType'>
Because sort has no return value
I just encountered this problem recently. The reason is that list1.sort() only sorts the elements in list1, and then returns NoneType. If you want to get the sorted list directly, you should use the sorted function.
You can use sorted
>>> list1=[3,2,5,6,1] >>> print sorted(list1) [1, 2, 3, 5, 6]
sorted returns a new list. sort sorts in place.
Because the function of list.sort() is to sort the elements of the list, rather than turning list.sort() itself into a sorted list
list.sort()
Because the type returned by the sort method of List is <type 'NoneType'>, your print here is not list1.
Because sort has no return value
I just encountered this problem recently. The reason is that list1.sort() only sorts the elements in list1, and then returns NoneType. If you want to get the sorted list directly, you should use the sorted function.
You can use sorted
sorted returns a new list. sort sorts in place.
Because the function of
list.sort()
is to sort the elements of the list, rather than turninglist.sort()
itself into a sorted list