godlikesuperbob 发表于 2022-4-2 16:29:26

删除语句里的del与pop

motorcycle = ['honda','yamaha','suzuki']
del motorcycle
print(motorcycle)

运算结果:
['yamaha', 'suzuki']



motorcycle = ['honda','yamaha','suzuki']
motorcycle.pop(0)
print(motorcycle)

运算结果:
['yamaha', 'suzuki']

请问这2个有什么区别吗?

isdkz 发表于 2022-4-2 16:44:36

你这样子没有区别,都是删除的作用,

但是 temp = motorcycle.pop(0) 这样子就有区别了,

这样可以把删除的元素赋给一个变量,而 del 删除则做不到
页: [1]
查看完整版本: 删除语句里的del与pop