python list列表函数

python list.clear()函数用于清空列表里面的所有元素。

语法

语法如下:
list对象.clear()
list.clear(list对象)

参数

没有参数

返回值

没有返回值,改变list的内部元素结构。

程序示例

#!/usr/bin/python
# coding=utf-8
list1 = ['a', 'b', 'c', 'd' ]
list1.clear()
print(list1) 

程序运行结果:

[]