【发布时间】:2020-05-21 10:41:04
【问题描述】:
在this answer 中声明您可以在 python 3 中使用return A+1 if A > B else A-1,但是当我尝试使用它时:
def max3(a,b,c):
return a if a > b and c
return b if b > c else c
我收到一个无效的语法错误。我已经尝试在网上查找,但我找不到任何关于此的内容,如果有人可以提供帮助,我将不胜感激。
谢谢。
【问题讨论】:
-
你错过了 else 部分
-
函数只能有一个返回
-
@rdas 函数可以有很多没有代码块的返回语句,但只有第一个可以生效
-
@YangHG *无条件退货声明
标签: python python-3.x return syntax-error