继续整理前段零零碎碎的python资料
一、字典补充
# 补充dict字典方法
dic={1:"china",2:"english",3:"american"}
# 取字典key,可以fon in遍历
k=dic.keys()
print(k) # dict_keys([1,2,3])
for i in k:
print(i)
# 取字典values
v=dic.values()
print(v) # dict_values(["china","english","american"])
# 将字典项取出(元组列表),方便for in以拆包方式遍历
kv=dic.items()
print(kv) # dict_items[(1,"china"),(2,"english"),(3,"american")]
for item in dic.items():
k,v=item
print(k,v)
解包:
a,b=(1,2)
a,b=[1,2]
|