标签:pytho dict spec ali nbsp color default python class
字典两大特点:无序,键唯一
创建字典
1 dic1 = {‘name‘:‘CatdeXin‘,‘age‘:22,‘bobby‘:‘学习‘,‘Speciality‘:‘跑步‘} 2 dic2 = dict(((‘name‘,‘CatdeXin‘),)) 3 print(dic1) 4 print(dic2)
对应操作
增
1 dic3 = {} 2 dic3[‘name‘] = ‘Miao‘ 3 dic3[‘age‘] = 12 4 print(dic3) 5 #{‘name‘: ‘Miao‘, ‘age‘: 12} 7 a = dic3.setdefault(‘name‘,‘yue‘) 8 b = dic3.setdefault(‘ages‘,18) 9 print(a,b) 10 #yue 18 11 print(dic3) 12 #{‘name‘: ‘yue‘, ‘ages‘: 18}
标签:pytho dict spec ali nbsp color default python class
原文地址:https://www.cnblogs.com/CatdeXin/p/10197766.html