python中怎么清空列表

Python (200) 2023-05-11 02:44:00

python中清空列表的方法是:可以利用clear()函数清空列表,类似于del a[:]。具体使用方法如:【list1 = ['Gogglll', 'phpppp', 'aoao', 'aidududu'];list1.clear()】。

clear() 函数用于清空列表,类似于del a[:]。

(推荐教程:Python入门教程)

注意:该方法没有返回值。

语法:

list.clear()

代码实现:

#!/usr/bin/python3
list1=['Google','phpcn','Taobao','Baidu']
list1.clear()
print("列表清空后:",list1)

输出结果:

列表清空后:[]
THE END

发表回复