Study Korner

Python Chapter#9: Python Dictionary

Ex:

d1 = {}
d1[123] = "Hello"
d1["World"] = 123
d2 = {";name": "jonny","Employee_code":6103467, "dept": "CSE"}
print(d1[123])         # Prints value for 'one' key
print(d1["World"])     # Prints value for 2 key
print(d2)              # Prints complete dictionary
print(d2.keys())       # Prints all the keys
print(d2.values())     # Prints all the values

OUTPUT:

Hello
123
{'Employee_code': 6103467, 'dept': 'CSE', 'name': 'jonny'}
dict_keys(['Employee_code', 'dept', 'name'])
dict_values([6103467, 'CSE', 'jonny'])
Python Dictionary Functions

Exit mobile version