PEP 308: Conditional Expressions - The Ternary Operator
TL;DR
PEP 308 introduced conditional expressions in Python 2.5 with the syntax value_if_true if condition else value_if_false
, providing a concise way to assign values based on conditions.
PEP 308 introduced conditional expressions in Python 2.5 with the syntax value_if_true if condition else value_if_false
, providing a concise way to assign values based on conditions.
PEP 572 introduced the walrus operator (:=) in Python 3.8, allowing assignment within expressions to reduce code duplication and improve readability.
The walrus operator gets its name from its resemblance to a walrus face - the colon represents the eyes and the equals sign represents the tusks!