Terms/Questions per Day

Terms

11 new/unreviewed 11 total

Term

Python 字典取值

Definition

1. [] 方括号取值 python 运行 print(d["name"]) # 张三 2. .get() 方法(最常用,安全) python 运行 print(d.get("name")) # 张三 print(d.get("height")) # 键不存在返回 None,不报错 print(d.get("height", 170)) # 键不存在,返回自定义默认值170 4. 遍历取值 获取所有键 .keys() python 运行 for k in d.keys(): print(k, d[k]) 6. 嵌套字典取值(多层) python 运行 info = {"user":{"name":"李四","addr":{"city":"广州"}}} # 方括号方式,一层错全部报错 print(info["user"]["addr"]["city"]) # get 安全写法 city = info.get("user",{}).get("addr",{}).get("city") print(city)

New/Unreviewed

Term

for i in range(3:9)

Definition

左闭右开

New/Unreviewed

Term

print() end=' ' flush=True

Definition

换行 结束换行 立刻刷新输出结果

New/Unreviewed
Practice Test Scores

Practice Tests

0 total
(None) Completed practice tests will show up here