I have been going through a tutorial on lambda functions and came across this line of code to evaluate if a number is odd or even. And I do not understand how the tow logic operators work in this function.
(lambda x: (x % 2 and 'odd' or 'even'))(5)
'odd'
A more "usual/readable" way of doing it might be:
(lambda x: 'even' if x % 2 == 0 else 'odd')(3)
'odd'
I do understand that x % 2 will return either 1 or 0 (truthy or falsey) and based on that the ensuing logic will work. What I do not understand is how the output of x % 2 is then used in the body of the function and how it computes if it is 'odd' or 'even' that is returned. It might have something to do with the priority of Pythonic operators but so far it is not very clear. Any help will be much appreciated.