Python3 List clear() method
Description
The clear() function is used to clear the list, similar todel a[:]。
Syntax
Syntax of clear() method:
list.clear()
Parameters
- None.
Return Value
This method has no return value.
Example
The following example demonstrates the usage of the clear() function:
Example
#!/usr/bin/python3
list1 = ['Google', 'Example', 'Taobao', 'Baidu']
list1.clear()
print ("After clearing the list : ", list1)
list1 = ['Google', 'Example', 'Taobao', 'Baidu']
list1.clear()
print ("After clearing the list : ", list1)
The output of the above example is as follows:
After the list is cleared: []Other Extensions