标签:values copy int bsp get for info 循环 返回
user_info = {"name":3,"age":11,"country":"china"} print(user_info["country"]) print(len(user_info)) for k in user_info: print(k) china 3 name country age
user_info = {"name":"Amy","age":11,"country":"china"} print(user_info.keys()) print(user_info.values()) print(user_info.items()) dict_keys([‘country‘, ‘age‘, ‘name‘]) dict_values([‘china‘, 11, ‘Amy‘]) dict_items([(‘country‘, ‘china‘), (‘age‘, 11), (‘name‘, ‘Amy‘)])
for k,v in user_info.items(): print(k) age country name
for k,v in user_info.items(): print(v) 11 china Amy
for k,v in user_info.items(): print(k,v) name Amy country china age 11
其他方法:
user_info = {"name":"Amy","age":11,"country":"china"} user_info.clear() print(user_info) {}
user_info = {"name":"Amy","age":11,"country":"china"} print(user_info.get("age")) print(user_info.get("sss")) 11 None
标签:values copy int bsp get for info 循环 返回
原文地址:https://www.cnblogs.com/yyxx8888/p/12637242.html