python中pop用法_python中pop()函数的用法

copycode.gif

sentence=['All', 'good', 'things', 'come', 'to' ,'those', 'who', 'wait.']

print("默认为 index=-1,删除最后一个列表值:",sentence.pop(-1),"\n")

print("默认删除最后一个列表值: ",sentence.pop(),"\n")

print("删除第一个元素:",sentence.pop(0),"\n")

print("删除第三个元素:",sentence.pop(2),"\n")

print("输出剩余元素:",sentence)

copycode.gif

二、 单独执行每一行print()函数:

copycode.gif

sentence=['All','good','things','come','to','those','who','wait']

print("默认为 index=-1,删除最后一个列表值:",sentence.pop(-1),"\n")

sentence1=['All','good','things','come','to','those','who','wait']

print("默认删除最后一个列表值:",sentence1.pop(),"\n")

sentence2=['All','good','things','come','to','those','who','wait']

print("删除第一个元素:",sentence2.pop(0),"\n")

sentence3=['All','good','things','come','to','those','who','wait']

print("删除第三个元素:",sentence3.pop(1),"\n")

你可能感兴趣的:(python中pop用法)