-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_6Dictionary.py
More file actions
65 lines (39 loc) · 1.04 KB
/
Python_6Dictionary.py
File metadata and controls
65 lines (39 loc) · 1.04 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Dictionary
Powerful and flexible datatype, which the collection of keyvalues
used to store data and also access that data
Syntax :
var_name = {} -----> empty dictionary
var_name = {"key":value, "key2":value2 }
just for example consider a hypothetical scenario where we own a restaurant
Dosa 60/-
Cold Coffee 80/-
Paneer tikka 100/-
Idli 120/-
Operations in Dictionary
"""
#Step 1 : Initialize a dictionary
menu = {} #empty
#Step 2 : How to add element
menu["Dosa"] = 60
menu["Cold Coffee"] = 80
menu["Paneer Tikka"] = 100
menu["Idli"] = 120
print(menu)
#Step 3 : How to remove a element
#del menu["Cold Coffee"]
#Step 4 : How to access the key
menu["Palak Paneer"] = 160
#print(PP_price)
#Step 5 : How to update
menu["Palak Paneer"] = 180
PP_price = menu["Palak Paneer"]
print(PP_price)
#Step 6 : How to clear a Dictionary
#menu.clear()
#Step 7 : How to find the length of the dictionary namely menu.
print(len(menu))
print(menu)
menu2 = {'Juice':30,'water':20,'Russian':6000}
print(menu2)
print(len(menu2))