I am trying to design a function that returns whether a or b is longer but I'm having a syntax error.
def get_longer(a:str, b:str):
return a if len(a) >= len(b) else return b
I have tried with a print statement and it is working however I need it to work with a return statement.
Any suggestions?
printisn't a statement, it is a function. You wantreturn a if len(a) >= len(b) else b. Or just write out the full if-else statementmax(a, b, key=len)