Practice:表格数据使用字典和列表存储,并实现访问

 1 r1 = {"name":"张三","age":18,"salary":30000,"city":"北京"}
 2 r2 = {"name":"李四","age":19,"salary":40000,"city":"上海"}
 3 r3 = {"name":"王二麻子","age":20,"salary":20000,"city":"深圳"}
 4 tb = [r1,r2,r3]
 5 
 6 #获得第二行的薪资
 7 print(tb[1].get("salary"))
 8 
 9 #打印表中所有人的薪资
10 for i in range(len(tb)):
11      print(tb[i].get("salary"))
12 
13 #打印表格
14 for i in range(len(tb)):
15      print(tb[i].get("name"),tb[i].get("age"),tb[i].get("salary"),tb[i].get("city"))