r1 = {'name':'July','age':18,'salary':30000,'city':'Beijing'} r2 = {'name':'Kryser','age':19,'salary':20000,'city':'Chengdu'} r3 = {'name':'Lili','age':20,'salary':10000,'city':'Shanghai'} tb = [r1,r2,r3] #获得第二行人的薪资 print(tb[1].get('salary')) print() #遍历所有的薪资 for i in range(len(tb)): #i-->0,1,2 print(tb[i].get('salary')) print() #打印表中所有数据 for i in range(len(tb)): print(tb[i].get('name'),tb[i].get('age'),tb[i].get('salary'),tb[i].get('city'))
#结果:
20000
30000
20000
10000
July 18 30000 Beijing
Kryser 19 20000 Chengdu
Lili 20 10000 Shanghai