>>> >>> a = [1,5,3,2] >>> sorted(a) [1, 2, 3, 5] >>> a [1, 5, 3, 2] >>> a.sort() >>> a [1, 2, 3, 5] >>> >>>
sorted(list) 和 list.sort()的不同之处:
使用sorted(list) 将改变list
使用list.sort() 不会改变list
>>> >>> a = [1,5,3,2] >>> sorted(a) [1, 2, 3, 5] >>> a [1, 5, 3, 2] >>> a.sort() >>> a [1, 2, 3, 5] >>> >>>