What Is Dictionary
What Is Dictionary
● A dictionary is a Mapping datatype consist of key-value pair separated by colon and all
● A dictionary is represented by { }.
● A dictionary is not a sequence and we can access element not by index but by their
keys.
D1={“A”:123,”B”:456}
D3=dict(D1) #Same as D1
D4=dict(zip(‘a’,’b’,’c’),(1,2,3)))
Zip function has separate keys braces and their values brackets
d=dict(a=1,b=2,c=3)
print(d)
2) get(): this function accepts key of dictionary and return its value
Traversing in Dictionary
d=dict(a=1,b=2,c=3)
1) for I in d:
print(I)
2) for I in d.keys():
Print(I)
3) for I in d.values():
print(I)
4) for I in d.items():
print(I)
D[‘a’]=100
● This will Update if ‘a’ key is present and if it is not in dictionary then will create new
key-value pair