AI engineering glossary · Python core
What is conditional expression?
Conditional expression (also called ternary operator): A one-line form value_if_true if condition else value_if_false that chooses between two values inside an expression. It is Python's ternary operator, suited to short choices, while longer logic belongs in a normal if statement.
Conditional expression: an example
label = 'pass' if marks >= 40 else 'fail' sets label to 'pass' when marks is 55.
Related terms
More Python core terms
Where you learn it
Conditional expression is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.