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!

30th Apr 2019, 9:48 AM
Thimira Rathnayake
Thimira Rathnayake - avatar
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
30th Apr 2019, 10:37 AM
Anna
Anna - avatar
0
Thanks! Anna
30th Apr 2019, 10:39 AM
Thimira Rathnayake
Thimira Rathnayake - avatar