小向阳 发表于 2017-3-4 19:53:15

求助

本帖最后由 小向阳 于 2017-3-4 19:56 编辑




我的版本是python2.7,reverse()不是倒序的吗?怎么会输出None?{:5_92:}

lubcat 发表于 2017-3-4 21:16:39

>>> list1 =
>>> list2 = list1.reverse()
>>> print(list2)
None

>>> type(list2)
<class 'NoneType'>
>>> type(list1.reverse())
<class 'NoneType'>
>>>

零度非安全 发表于 2017-3-4 22:04:58

s.reverse() reverses the items of s in place

Note:The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they operate by side effect, they don’t return the sorted or reversed list.

donkkong 发表于 2017-3-4 22:07:22

>>> list1 =
>>> list1

>>> list1.reverse()
>>> list1

>>> list2 = list1
>>> list2

>>> list3 = list2[-1::-1]
>>> list3

>>>

小向阳 发表于 2017-3-11 17:03:10

lubcat 发表于 2017-3-4 21:16


谢谢啦

小向阳 发表于 2017-3-11 17:03:52

donkkong 发表于 2017-3-4 22:07
>>> list1 =
>>> list1



嗯嗯 会啦   谢谢啦

donkkong 发表于 2017-3-11 18:14:10

不客气,加油
页: [1]
查看完整版本: 求助