50 Program to demonstrate methods and functions of Dictionary in Python

Program 1:
#getting keys and values

material={"books":10,"pens":20,"chairs":30}

print(material.keys())  #prints all keys

print(material.values()) #prints all values


Program 2:
#methods of dictionary

x={"name":"amar","branch":"CSE","Rank":5}

print(x)

print(id(x))

print(x["name"])

print(x.get("name"))

x.pop("branch") #removing particular key

print(x)

x.popitem()    #randomly any key will b removed

print(x)

print(x.clear())

print(type(x),len(x),id(x))



Output:

Program to demonstrate methods and functions of Dictionary in Python

Previous
Next Post »