如何删除列表citys中的所有元素?
列表 citys=[‘wh’,’bj’,’gz’,’sh’,’tj’]
1、
citys=['wh','bj','gz','sh','tj']
del citys[0:5]
print(citys)
打印结果:[ ]
2、
citys=['wh','bj','gz','sh','tj']
del citys[-5:]
print(citys)
打印结果:[ ]
3、
citys=['wh','bj','gz','sh','tj']
del citys[:]
print(citys)
打印结果:[ ]
4、
citys=['wh','bj','gz','sh','tj']
citys1=['wh','bj','gz','sh','tj']
if citys:
for city in citys1:
citys.remove(city)
print(citys)
打印结果:[ ]
5、
citys=['wh','bj','gz','sh','tj']
citys1=['wh','bj','gz','sh','tj']
if citys:
for city in citys1:
citys.remove(city)
print(citys)
打印结果:
[‘bj’, ‘gz’, ‘sh’, ‘tj’]
[‘gz’, ‘sh’, ‘tj’]
[‘sh’, ‘tj’]
[‘tj’]
[ ]