Header Ads

Responsive Ads Here

Dictionary methods

 Dictionary Methods



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

# fromkeys
my_dict = dict.fromkeys(("name", "age", "fav_col"), "N/A")
print(my_dict)

# get
# print(d["fav"])
print(d.get("fav","Not Found!"))

# copy
d1 = d.copy()
d1["fav_col"] = "Purple"
print(d1)
print(d)


# clear
d.clear()
print(d)

 

Powered by Blogger.