示例示例Python清空列表有两种方法:使用clear()方法:
Python清空列表有两种方法:
1. 使用clear()方法:
python
list = [1, 2, 3, 4]
list.clear()
print(list)
# 输出结果 []
2. 使用del语句:
python
list = [1, 2, 3, 4]
del list[:]
print(list)
# 输出结果 []
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(86条)