Ternary conditional operator | Sololearn: Learn to code for FREE!


Ternary conditional operator

Does python have ternary conditional operator?

5/4/2021 6:50:18 PM

Kìrā Çhââñâ

2 Answers

New Answer


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-python/


yes, it works like so res = True if x > y else False it's just a bit different than other languages