Crossin的编程教室
标题:
.pop(-1)中的-1怎么理解?
[打印本页]
作者:
hunsjie
时间:
2013-11-11 09:02
标题:
.pop(-1)中的-1怎么理解?
def
print_last_word
(words):
"""Prints the last word after popping it off."""
word
=
words
.
pop(
-
1
)
print
word
https://learn-python-the-hard-way-zh_cn-translation.readthedocs.org/en/latest/ex25.html
如图所示,为什么输出的结果是删除最后一个单词,-1怎么理解?
作者:
vose
时间:
2013-11-11 11:21
e.g. pop(-1) 就是拿掉倒数第一个
x=[1,2,3,4,5]
x.pop(-1)
print x
x = [1,2,3,4]
复制代码
欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/)
Powered by Discuz! X2.5