+ 2

Ternary conditional operator

Does python have ternary conditional operator?

4th May 2021, 6:50 PM
RealEmmaPlays
RealEmmaPlays - avatar
2 ответов
+ 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/
4th May 2021, 6:59 PM
RKK
RKK - avatar
+ 1
yes, it works like so res = True if x > y else False it's just a bit different than other languages
4th May 2021, 7:00 PM
Apollo-Roboto
Apollo-Roboto - avatar