+2 votes
in Programming Languages by (77.8k points)
How to delete all elements from a list?

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

To delete all items from a list, you can use del statement or clear().

Approach 1 (Python 3 only)

a=[11,12,13,14,15,16]
a.clear()
print(a)

[]

Approach 2 (both Python 2 and 3)

a=[11,12,13,14,15,16]
del a[:]
print(a)

[]

Related questions

+2 votes
1 answer
+5 votes
1 answer
+4 votes
1 answer
+5 votes
1 answer

...