【发布时间】:2019-02-18 20:33:55
【问题描述】:
我正在寻找一种在字典中使用 if else 条件来为键设置值的方法。有什么办法吗?
下面的示例可能会帮助您了解我想要做什么。这不是功能性 Python 代码。只是一个例子给你一个想法。
age = 22
di = {
'name': 'xyz',
if age>=18:
'access_grant': 'yes',
else:
'access_grant': 'no',
}
【问题讨论】:
标签: python python-3.x if-statement