Python dictionary of reading

Read all the keys dictionary

D={"键1":"值1","key2":"value2"}
A=D.keys()		# 获取字典D的所有建
B=D.values()   # 获取字典D的所有值
print(A)    # A 的数据类型为<class 'dict_keys'>
print(B)    # B 的数据类型为<class 'dict_values'>

Results:
Here Insert Picture Description
the dictionary output value (to be output for the same reason bond)

D={"键1":"值1","key2":"value2"}
for i in  D.values():
    print("字典D的值:%s"%i)

The results are:
Here Insert Picture Description
the use of all keys of a for loop

D={"键1":"值1","key2":"value2"}
for i in  D.items():
    print(i)

The results are:
Here Insert Picture Description
the dictionary key and worth query
https://blog.csdn.net/GrofChen/article/details/91489121
all dictionaries built-in functions
https://blog.csdn.net/GrofChen/article/details/91371816

Guess you like

Origin blog.csdn.net/GrofChen/article/details/91488972