Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 List clear() Method

Python3 List clear() Method

Python3 Lists The Python3 list


Description

The clear() function empties a list, similar to del a[:]。

Syntax

clear() method syntax:


list.clear()

Parameters

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

(

)

print

(

"After the list is cleared: "

,

list1

)

The output of the above example is:


列表清空后 :  []

Python3 Lists The Python3 list