-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_dictionary.py
More file actions
36 lines (27 loc) · 1.09 KB
/
17_dictionary.py
File metadata and controls
36 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# A Python dictionary is a data structure that stores the value in key: value pairs.
# Values in a dictionary can be of any data type and can be duplicated, whereas keys
# can’t be repeated and must be immutable.
# key value pair
# dictionary
# object
# hash table
# overlap with set
person = {'name' : 'Aminul Islam', 'address' : 'Ctg', 'age' : 34}
print(person) # {'name': 'Aminul Islam', 'address': 'Ctg', 'age': 34}
print(person['name']) # Aminul Islam
print(person.keys()) # dict_keys(['name', 'address', 'age'])
print(person.values()) # dict_values(['Aminul Islam', 'Ctg', 34])
person['language'] = 'Eng'
print(person) # {'name': 'Aminul Islam', 'address': 'Ctg', 'age': 34, 'language': 'Eng'}
person['name'] = 'Amin'
print(person) # {'name': 'Amin', 'address': 'Ctg', 'age': 34, 'language': 'Eng'}
del person['age']
print(person) # {'name': 'Amin', 'address': 'Ctg', 'language': 'Eng'}
as_list = list(person)
print(as_list) # ['name', 'address', 'language']
for key, values in person.items():
print(key, values)
""" name Amin
address Ctg
language Eng
"""