1.元组
dic.count()
dic.index()
字典
1.fromkeys
dic={'k1'='v1','k2'='v2'}
new_dic=dic.from.fromkeys(['k1','k2','k3'],'v1')
print(new_dic)#返回{'k1':'v1','k2':'v1','k3':'v1'}
2.get
dic={'k1'='v1','k2'='v2'}
print(dic.get('k1'))
print(dic.get('k2'))
print(dic.get('k3'))当没有K3时返回一个none print(dic.get('k3':'lgs'))设置一个默认值
3.keys values items
dic={'k1'='v1','k2'='v2'}
print(dic.keys()) 返回 dic.keys(['k1','k2'])
print(dic.values())返回 dic.values(['v1','v2'])
print(dic.items())返回 dic.items([('k1','v1'),('k2','v2')])
等价于
for k in dic.keys()
print (k)
for v in dic.values()
print(v)
for k,v in dic.items()
print(k,v)
4.pop
dic.pop(k1)必须指定参数,因为字典是无序的
5.pop.item 随机取走一对key values
dic={'k1'='v1','k2'='v2'}
dic.popitem()
print(dic)
6.update 新增一对值
dic={'k1'='v1','k2'='v2'}
dic.update({'k3':'v3'})
print(dic)