python中怎么清空列表

503次阅读
没有评论

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

python中怎么清空列表

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

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

语法:

list.clear()

代码实现:

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

输出结果:

列表清空后 :  []
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-06-12发表,共计292字。
新手QQ群:570568346,欢迎进群讨论 Python51学习