Which Python ternary operation is better and why?

I read everywhere, including Does Python have a ternary conditional operator? . It is assumed that

result = a if a > b else b

better code than

result =  a > b and a or b

But no one ever explains why. Someone please clarify?

If this is simple readability, then it really is a matter of preference: some people will like one thing, and some will love the other. Therefore, my question is: are there any really technical advantages in order to go one way against another?

+5
source share
1 answer

result = a if a > b else b , . , , , a, b. result = a > b and a or b b , a - (0, None ..).

, a if x else b , , , Python. , , , , , .

+14

All Articles