|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> a = [1,2,3,4,5,6]
>>> a.reverse()
>>> a.sort()
>>> list.reversed(a)
Traceback (most recent call last):
File "<pyshell#99>", line 1, in <module>
list.reversed(a)
AttributeError: type object 'list' has no attribute 'reversed'
>>> list.(reversed(a))
SyntaxError: invalid syntax
- >>> list1 = [1,3,4,2,3,0,6]
- >>> list1.sort() #按从小到大排序
- >>> list1
- [0, 1, 2, 3, 3, 4, 6]
复制代码
-------------------------------------------------
- >>> list1 = [1,3,4,2,3,0,6]
- >>> list1.reverse() #这只是把列表倒序,并没有按其他规律排序
- >>> list1
- [6, 0, 3, 2, 4, 3, 1]
- >>>
复制代码
-----------------------------------------------
- >>> list1 = [1,3,4,2,3,0,6]
- >>> sorted(list1) #只是把列表从小到大排序的结果显示出来,但是list1事实上没有任何变化
- [0, 1, 2, 3, 3, 4, 6]
- >>> list1
- [1, 3, 4, 2, 3, 0, 6]
- >>>
复制代码
-----------------------------------------------
- >>> list1 = [1,3,4,2,3,0,6]
- >>> reversed(list1) #这只是生成列表的迭代器,需要借助list来查看倒序的结果,但是list1事实上也没有任何改变
- <list_reverseiterator object at 0x00000000030A8748>
- >>> list1
- [1, 3, 4, 2, 3, 0, 6]
- >>> list(reversed(list1)) #查看结果
- [6, 0, 3, 2, 4, 3, 1]
- >>> list1
- [1, 3, 4, 2, 3, 0, 6]
- >>>
复制代码
|
|