python:数字列表时对字符串列表进行排序

eta*_*luz 0 python sorting list

新手在这里使用python解释器。

为什么我不能对这个字符串列表进行排序?

>>> list = ['296098', '12805', '10445635', '11679960']
>>> print list.sort()
None
>>> print list.sort(key=float)
None
Run Code Online (Sandbox Code Playgroud)

为什么python无法为我排序此字符串列表?

Are*_*res 5

list.sort() 对列表进行适当的更改,而不是返回新列表。

>>> list = ['296098', '12805', '10445635', '11679960']
>>> list.sort()
>>> list
['10445635', '11679960', '12805', '296098']
Run Code Online (Sandbox Code Playgroud)