Skip to content Skip to sidebar Skip to footer

Can We Chain The Ternary Operator In Python?

Can we chain the ternary operator in Python? We can do it for multiple if conditions in Java. Can that be done in Python too?

Solution 1:

Yes.

x = 'x' if 1<0 else 'y' if 0<1 else 'z'

Post a Comment for "Can We Chain The Ternary Operator In Python?"