Header Ads

Responsive Ads Here

Adding and Deleting Data (Dictionaries)

 Adding and Deleting Data (Dictionaries)



d = {"name" : "Adrika", "age": 14, "class" : 9}

# adding data to dictionary
d["Fav_color"] = "Purple"
print(d)

# deleting data from dictionary
# pop
l = [1,2,3,4,5]
l.pop()
print(l)

x = d.pop("class")
print(x)
print(type(x))
print(d)

# popitem  ---> randomly deletes the key:value pair

d.popitem()
print(d)

# update

my_dict = {"name": "Adrika", "age": 14}
new_d = {"name":"Anika", "Fav_song": "ON", "Fav_food": "Pizza"}
my_dict.update(new_d)
print(my_dict)

Powered by Blogger.