In my textbook I came across this example:
lower = (lambda x, y: x if x < y else y)
print(lower ('bb','aa'))
So far I used
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
So, this ‘x if x < y else y’ astonished me a bit.
Could you direct me: where in the documentation can I find this construction?
Thank you in advance
So they are called “Conditional Expressions” and you can find them in the python 3 docs a longer clearer explanation can be found in this section of of the 2.5 docs. I use it a lot for conditional assignment like: