Friday 4 December 2015

Python: list: clear all elements in the list

List provides ‘clear’ method to clear all elements in the list.

test.py

list=[2, 4, 6, 6, 4, 2]
print(list)

list.clear()
print(list)

$ python3 test.py
[2, 4, 6, 6, 4, 2]
[]



Previous                                                 Next                                                 Home

No comments:

Post a Comment