dic = {'名字': '小明', '身高': 168, '体重': 55} print(dic['名字'] + '的身高是' + str(dic['身高']) + 'cm,' + '体重是' + str(dic['体重']) + 'kg.')
打印字典中的整形时记得转成字符串
# 定义空字典 dic = {} print(dic) # 添加键值对 dic['名字'] = '小明' dic['身高'] = 165 dic['体重'] = 55 # 打印字典 print(dic)
添加键值对
dic = {'名字': '小明', '身高': 168, '体重': 55} print(dic['名字'] + '的身高是' + str(dic['身高']) + 'cm,' + '体重是' + str(dic['体重']) + 'kg.') dic['身高'] = 178 dic['体重'] = 88 print(dic)
修改字典
标签:str,python,dic,学习,体重,print,身高,字典 From: https://www.cnblogs.com/pingu-1/p/17965171