Questions

How do you Del Statement in Python?

To delete a variable or an object in Python, we use the following syntax –

                    

del obj_name[optional]

where,

obj_name = name of the variable, user-defined object, list, tuple, set, dictionary, etc.

[optional] = Index value for slicing/deleting specific data elements from the object iterables.

Example

                    

games = ['cricket', 'football', 'hockey', 'golf', 'chess']

del games[2]
print('Games list:', games)
print()

food = ['burger', 'pizza', 'pattice', 'sandwich']
del food
print(food)

Output

                    

Games list: ['cricket', 'football', 'golf', 'chess']

Traceback (most recent call last):
File "", line 9, in 
NameError: name 'food' is not defined

Related Questions

Related Topics

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

avatar
  Subscribe  
Notify of

Customize your course in 30 seconds

Which class are you in?
No thanks.