-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2_dict.py
More file actions
30 lines (26 loc) · 1.05 KB
/
Copy pathday2_dict.py
File metadata and controls
30 lines (26 loc) · 1.05 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
# dict
school={"name": "ABC School", "location": "New York"}
school1={"name": "XYZ School", "location": "Los Angeles"}
add_school= school | school1
print(add_school)# Output: {'name': 'XYZ School', 'location': 'Los Angeles'} old value overwritten
school={"name": "ABC School", "location": "New York"}
school_info={"students": 500, "teachers": 30}
add_school= school | school_info
print(add_school) # Output: {'name': 'ABC School', 'location': 'New York', 'students': 500, 'teachers': 30} new key-value pairs added
student={"name": "John", "age": 20,
"subjects":{"Math": 85, "Science": 90}}
print(student)
print(student["subjects"]["Math"]) # Output: 85
print(student.get("subjects"))
print(student.get("subjects").get("Science"))
print(student.keys())
print(student.values())
print(student.items())
print(len(student))
student["gender"]={"Male","Female"}# Adding a new key-value pair we canuse list dict or set as value
print(student)
#add new subject
student["subjects"]["English"]=88
print(student)
student_copy=student.copy() # Shallow copy
print(student_copy)