dic = {"name": "Fox", "profession": "Programmer", "salary": 13500}
s = dic["name"]
print("1.", s)
s = dic.get("name")
print("2.", s)
dic["salary"] = "14000"
print("3.", dic, "\n")
for item in dic:
print(item)
print("\n4.")
for item in dic:
print(dic[item])
print("\n5.")
for val in dic.values():
print(val)
print("\n6.")
for key, val in dic.items():
print(key, val)
if "name" in dic:
print("7. yes")
print("8.", len(dic))
dic["id"] = "726482"
print("9.", dic)
dic.pop("id")
print("10.", dic)
dic.popitem() # before versions 3.7 random item will removed
print("11.", dic)
del dic["profession"]
print("12.", dic)
dic = {"name": "Fox", "profession": "Programmer", "salary": 13500}
dic1 = dic.copy()
print("13.", dic1)
dic1.clear()
print("14.", dic1)
dic2 = dic.fromkeys("name", "Fox")
print("15.", dic2)
s = dic.items()
print("16.", s)
s = dic.keys()
print("17.", s)
s = dic.values()
print("18.", s)
dic.update({"id": "876341"})
print("19.", dic)
s = dic.setdefault("salary")
print("20.", s)
s = dic.setdefault("age", 52) # key does not exist, insert the key, with the value
print("21.", s)
print("22.", dic)
del dic
# print("23.", dic) # Error: name 'dic' is not defined
'''
run:
1. Fox
2. Fox
3. {'name': 'Fox', 'salary': '14000', 'profession': 'Programmer'}
name
salary
profession
4.
Fox
14000
Programmer
5.
Fox
14000
Programmer
6.
name Fox
salary 14000
profession Programmer
7. yes
8. 3
9. {'name': 'Fox', 'id': '726482', 'salary': '14000', 'profession': 'Programmer'}
10. {'name': 'Fox', 'salary': '14000', 'profession': 'Programmer'}
11. {'salary': '14000', 'profession': 'Programmer'}
12. {'salary': '14000'}
13. {'name': 'Fox', 'profession': 'Programmer', 'salary': 13500}
14. {}
15. {'n': 'Fox', 'm': 'Fox', 'e': 'Fox', 'a': 'Fox'}
16. dict_items([('name', 'Fox'), ('salary', 13500), ('profession', 'Programmer')])
17. dict_keys(['name', 'salary', 'profession'])
18. dict_values(['Fox', 13500, 'Programmer'])
19. {'name': 'Fox', 'id': '876341', 'salary': 13500, 'profession': 'Programmer'}
20. 13500
21. 52
22. {'name': 'Fox', 'id': '876341', 'salary': 13500, 'age': 52, 'profession': 'Programmer'}
'''