删除语句里的del与pop
motorcycle = ['honda','yamaha','suzuki']del motorcycle
print(motorcycle)
运算结果:
['yamaha', 'suzuki']
与
motorcycle = ['honda','yamaha','suzuki']
motorcycle.pop(0)
print(motorcycle)
运算结果:
['yamaha', 'suzuki']
请问这2个有什么区别吗? 你这样子没有区别,都是删除的作用,
但是 temp = motorcycle.pop(0) 这样子就有区别了,
这样可以把删除的元素赋给一个变量,而 del 删除则做不到
页:
[1]