阿神2017-04-17 15:43:36
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'>
PHPz2017-04-17 15:43:36
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.
PHP中文网2017-04-17 15:43:36
You can use sorted
>>> list1=[3,2,5,6,1]
>>> print sorted(list1)
[1, 2, 3, 5, 6]
伊谢尔伦2017-04-17 15:43:36
Because the function of list.sort()
is to sort the elements of the list, rather than turning list.sort()
itself into a sorted list