编程语言
首页 > 编程语言> > Python学习笔记018

Python学习笔记018

作者:互联网

字典

排序

dic={'name':23,'age':39,'job':48,'marriage':11}
print(dic)

print(sorted(dic))

print(sorted(dic.keys()))
print(sorted(dic.values()))
print(sorted(dic.items()))

遍历

dic={'name':'Kevin','age':39,'job':'teacher','marriage':True}
print(dic)

for i in dic:
print(i)

#推荐
for i in dic:
print(i,dic[i])

#不推荐,转换需要时间
for i in dic.items():
print(i)

for i,v in dic.items():
print(i,v)

标签:Python,items,笔记,dic,print,job,marriage,018,sorted
来源: https://www.cnblogs.com/wtzxxy/p/12418316.html