智一面的面试题提供python的测试题
1)get():强烈推荐的字典元素访问方式(这种方式最好最常用)
a = {"name":"张三","age":18,"job":"teacher"}
display(a)
display(a.get("name"))
display(a.get("weight"))
结果如下:
2)items():获取字典中的键值对;
a = {"name":"张三","age":18,"job":"teacher"}
display(a)
display(a.items)
for i in a.items():
print(i)
结果如下:
3)keys():获取字典中所有的键;values():获取字典中所有的值;
a = {"name":"张三","age":18,"job":"teacher"}
display(a)
display(a.keys())
display(a.values())
结果如下:
————————————————