del() method: This method is used to delete any item from the dictionary.
d={1:"mayank",2:"aniket",3:"prajapati"}
del(d[1])
print(d) # {2: 'aniket', 3: 'prajapati'}
clear() method: This function is used to delete all the values from the dictionary and our dictionary will be emptied after executing this function.
d={1:"mayank",2:"aniket",3:"prajapati"}
d.clear()
print(d) # {}
copy() function: This function is used to copy all the items of dictionary into another object.
d={1:"mayank",2:"aniket",3:"prajapati"}
e=d.copy()
print(e) # {1:"mayank",2:"aniket",3:"prajapati"}
pop(): This function will take key as an argument. This function will only return value not the item.
d={1:"mayank",2:"aniket",3:"prajapati"}
x=d.pop(1)
print(x) # "mayank"
print(d) # {2:"aniket",3:"prajapati"}
popitem(): This function does not require any argument. It will randomly remove an item from the dictionary and return that item as a tuple.
d={1:"mayank",2:"aniket",3:"prajapati"}
x=d.popitem()
print(type(x)) # tuple
print(x) # (3, 'prajapati')
print(d) # {1:"mayank",2:"aniket"}
d={1:"mayank",2:"aniket",3:"prajapati"}
del(d[1])
print(d) # {2: 'aniket', 3: 'prajapati'}
clear() method: This function is used to delete all the values from the dictionary and our dictionary will be emptied after executing this function.
d={1:"mayank",2:"aniket",3:"prajapati"}
d.clear()
print(d) # {}
copy() function: This function is used to copy all the items of dictionary into another object.
d={1:"mayank",2:"aniket",3:"prajapati"}
e=d.copy()
print(e) # {1:"mayank",2:"aniket",3:"prajapati"}
pop(): This function will take key as an argument. This function will only return value not the item.
d={1:"mayank",2:"aniket",3:"prajapati"}
x=d.pop(1)
print(x) # "mayank"
print(d) # {2:"aniket",3:"prajapati"}
popitem(): This function does not require any argument. It will randomly remove an item from the dictionary and return that item as a tuple.
d={1:"mayank",2:"aniket",3:"prajapati"}
x=d.popitem()
print(type(x)) # tuple
print(x) # (3, 'prajapati')
print(d) # {1:"mayank",2:"aniket"}
Be First to Post Comment !
Post a Comment