【问题标题】:Functions and variable assignment Python [duplicate]函数和变量赋值Python [重复]
【发布时间】:2015-03-21 06:56:25
【问题描述】:
a=[8,2,15,6,1]
a = a.sort()
print a

为什么打印None?您能详细说明所有功能吗?

【问题讨论】:

  • 不要将 a.sort() 分配给 a。只需对其进行排序并打印一个

标签: python list sorting


【解决方案1】:

sort()sorted() 不同:

  • sort() 对列表进行就地排序并返回 None
  • sorted() 创建一个新列表并将其返回。

更多详情请参阅here

【讨论】:

    猜你喜欢
    • 2013-03-31
    • 2013-09-13
    • 2017-12-18
    • 2016-03-27
    • 2014-05-06
    • 1970-01-01
    • 2011-10-11
    • 2016-02-03
    相关资源
    最近更新 更多