python del command code example
Example 1: python del
# Delete Variables
my_var = 5
my_tuple = ('Sam', 25)
my_dict = {'name': 'Sam', 'age': 25}
del my_var
del my_tuple
del my_dict
# Delete item from list
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# deleting the third item
del my_list[2]
# Delete from dictionary
person = { 'name': 'Sam',
'age': 25,
'profession': 'Programmer'
}
del person['profession']
Example 2: del list python
>>> a=[1,2,3]
>>> a.remove(2)
>>> a
[1, 3]
>>> a=[1,2,3]
>>> del a[1]
>>> a
[1, 3]
>>> a= [1,2,3]
>>> a.pop(1)
2
>>> a
[1, 3]
>>>