Python List clear() method
Python List clear() method
The list.clear () method in Python extends the list by appending all the items from the iterable.
Syntax
list.clear()
Parameter
NA
Example 1
# Python Program explaining # the list.clear() method week_list = ["Monday", "Tuesday", "Wednesday","Thursday","Friday", "Saturday"] print("List before calling clear() method\n", week_list) # clearing off the week_list week_list.clear() print("After calling the clear() method\n",week_list)
Output
List before calling clear() method ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] After calling the clear() method []
Example 2
# Python Program explaining # the list.clear() method val = {16, 10, 14, 11} print('val before clear:', val) # clearing numbers val.clear() print('val after clear:', val)
Output
val before clear: {16, 10, 11, 14} val after clear: set()