0
What does 'lambda functions can't have statements' mean?
I tried to understand this using 'if', 'for' and 'while' inside a lambda function, 'for' and 'while' gave an error after executed, but 'if' didn't. Is 'if' not a statement or have I no idea about statements at all!
2 ответов
+ 5
if is a statement, but there's a special syntax that allows you to use if in a lambda function:
greater = lambda m, n: m if m > n else n
This syntax is python's equivalent to the ternary operator (a ? b : c) in other languages
0
Thanks! Anna