Python3 List clear() Method
Description
The clear() function empties a list, similar to del a[:]。
Syntax
clear() method syntax:
list.clear()
Parameters
- none.
Return Value
This method has no return value.
Example
The following example shows how to use the clear() function:
Example
#!/usr/bin/python3
list1
=
[
'Google'
,
'Runoob'
,
'Taobao'
,
'Baidu'
]
list1.
clear
(
)
(
"After the list is cleared: "
,
list1
)
The output of the above example is:
列表清空后 : []
The Python3 list