Skip to content

del list Python | Example code

  • by

Using the del keyword can delete list objects in Python. It will delete the whole list.

del thislist

Example del list Python

Simple example code print list after deleted it.

this_list = ["apple", "banana", "cherry"]

del this_list

print(this_list)

Output:

del list Python

You can also remove elements from a list with del statements. Just pass the index value inside the brackets [].

l = list(range(6))
print(l)

del l[0]
print(l)

Output:

[0, 1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]

Do comment if you have any doubts or suggestions on this Python list topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading