-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdictionary_methods.py
More file actions
49 lines (40 loc) · 959 Bytes
/
Copy pathdictionary_methods.py
File metadata and controls
49 lines (40 loc) · 959 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
n = {'nishit': 'patel', <----'key':'value'
'ford': 'car',
'bmw': 1956}
print(n)
# GET method
x = n.get('nishit')
print(x)
# OUTPUT = patel
# CHANGE value
n['nishit'] = 'ravi'
print(n)
# OUTPUT = {'nishit': 'ravi', 'ford': 'car', 'bmw': 1956}
# ADD dict
n['ravi'] = 'boss'
print(n)
# OUTPUT = {'nishit': 'patel', 'ford': 'car', 'bmw': 1956, 'ravi': 'boss'}
# REMOVE method
n.pop('nishit')
print(n)
# OUTPUT = {'ford': 'car', 'bmw': 1956}
# DEL method
del n['ford']
print(n)
# OUTPUT = {'nishit': 'patel', 'bmw': 1956}
# CLEAR method
n.clear()
print(n)
# OUTPUT = {}
# KEY method
m = n.keys()
print(m)
# OUTPUT = dict_keys(['nishit', 'ford', 'bmw'])
# UPDATE method
n.update({'color' : 'red'})
print(n)
# OUTPUT = {'nishit': 'patel', 'ford': 'car', 'bmw': 1956, 'color': 'red'}
# SET default
m = n.setdefault('nishit' , 'patidar')
print(m)
# OUTPUT = patel