Python sort

来源:互联网 发布:海康摄像头无网络视频 编辑:程序博客网 时间:2024/06/05 03:25

sort()是没有返回值的 只是做了一个操作 对序列进行更改 

所以 如果你有一个list=[1,2,3,4,5] 你sort()了 那么 那就再真的sort()了 

你还想使用原来的 最好复制一份 而且 copy=list是没用的

你要another_copy=[1,2,3,4,5]

list=['4','5','w','a','g','14','ac']another_list =['4','5','w','a','g','14','ac']copy=listprint 'list is         '+str(list)print list.sort()print 'sorted list is  '+str(list)print 'another list is '+str(another_list)print 'copy is         '+str(copy)

>>>

list is         ['4', '5', 'w', 'a', 'g', '14', 'ac']
None
sorted list is  ['14', '4', '5', 'a', 'ac', 'g', 'w']
another list is ['4', '5', 'w', 'a', 'g', '14', 'ac']
copy is         ['14', '4', '5', 'a', 'ac', 'g', 'w']