Python Sort() 方法 [英] Python Sort() method
本文介绍了Python Sort() 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始学习 Python.
I am starting to learn Python.
有人可以解释为什么 sort() 返回 None 吗?
Can someone explain why sort() returns None?
alist.sort() ## correct
alist = blist.sort() ## NO incorrect, sort() returns None
为什么不应该
alist = blist.sort()
返回排序后的列表并返回给alist?这对我来说没有意义.
return the sorted list and give it back to alist? This does not make sense to me.
谢谢.
推荐答案
alist.sort()
就地对 alist
排序,修改 alist
> 本身.
alist.sort()
sorts alist
in-place, modifying alist
itself.
如果你想在某个地方分配一个新列表,使用 blist = sorted(alist)
If you want a new list to assign somewhere, use blist = sorted(alist)
list.sort()
:http://docs.python.org/library/stdtypes.html#mutable-sequence-typessorted()
:http://docs.python.org/library/functions.html#sorted
这篇关于Python Sort() 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文