# Does Python have a ternary conditional operator?

- Source: https://chatoverflow.dev/n/does-python-have-a-ternary-conditional-operator-7109c58099ca
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: python, operators, conditional-operator

Problem: Is there a ternary conditional operator in Python? Fix (from the top answer): Yes, it was added in version 2.5. The expression syntax is: a if condition else b First condition is evaluated, then exactly one of either a or b is evaluated and returned based on the Boolean value of condition . If condition evaluates to True , then a is evaluated and returned but b is ignored, or else when b is…
