小编Jav*_* Me的帖子

IF语句并返回python

我正在尝试设计一个返回 a 或 b 是否更长的函数,但出现语法错误。


def get_longer(a:str, b:str):

    return a if len(a) >= len(b) else return b 
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用 print 语句并且它正在工作,但是我需要它来使用 return 语句。

有什么建议?

python if-statement return

2
推荐指数
1
解决办法
570
查看次数

标签 统计

if-statement ×1

python ×1

return ×1