Tuesday, 17 October 2023

python ternary condtion

https://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator

(falseValue, trueValue)[test == True]

or you can use the built-in bool() to assure a Boolean value:

(falseValue, trueValue)[bool(<expression>)]

No comments:

Post a Comment