如何在内联命令中使用(walrus运算符:=
)
与此相反:
>>> result = None
>>> if res := message.from_user:
>>> result = res.id
>>> else:
>>> result = message.chat.id
例如,可以这样写吗
>>> ID = result.id if result := message.from_user else message.chat.id
SyntaxError: invalid syntax
可能吗
我使用此模式时出错 如何编写以避免错误
walrus运算符的优先级较低,因此需要在条件表达式中使用它
相关问题 更多 >
编程相关推荐