condition_value = 1
val = 1 if condition_value == 1 else 2
print val
Ternary operators are useful to assign the condition-based return value. You can use ternary operators in python by using the below syntax
[if_condition_true] if [if_condition] else [if_condition_false]
0 Comments