码迷,mamicode.com
首页 > 编程语言 > 详细

python中list.sort()与sorted()的区别

时间:2019-05-02 21:30:44      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:color   ref   lis   htm   python   内置函数   http   col   ocs   

list.sort()和sorted()都是python的内置函数,他们都用来对序列进行排序,区别在于

  • list.sort()是对列表就地(in-place)排序,返回None;sorted()返回排好序的新列表,原列表不变
  • list.sort()只适用于列表,sorted()适用于任意可迭代对象

参考链接:Sorting HOW TO

python中list.sort()与sorted()的区别

标签:color   ref   lis   htm   python   内置函数   http   col   ocs   

原文地址:https://www.cnblogs.com/zzliu/p/10803320.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!