+ 2
Ternary conditional operator
Does python have ternary conditional operator?
2 Antworten
+ 2
Yes!
Generally,
var = [on_true] if [expression] else [on_false]
for example: (finding the minimum from two numbers)
a, b = 10, 20
min = a if a < b else b
src: https://www.geeksforgeeks.org/ternary-operator-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
+ 1
yes, it works like so
res = True if x > y else False
it's just a bit different than other languages