when to use dictionary in python code example
Example 1: how to use dictionaries in python
student_data = {
"name":"inderpaal",
"age":21,
"course":['Bsc', 'Computer Science']
}
print(student_data['name'])
print(student_data['age'])
print(student_data['course'])[0]
Example 2: dictionary in python
tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
print(tel)
print(tel['jack'])
del tel['sape']
tel['irv'] = 4127
print(tel)
print(list(tel))
print(sorted(tel))
print('guido' in tel)
print('jack' not in tel)
Example 3: dictionary in python
dict = {
"key": "value",
"other_key": "value"
}
print(dict["key"])
print(dict[1])