Keywords and Expressions

or — Short-circuit disjunction

Evaluate the left operand and return it if truthy; otherwise evaluate and return the right operand. This is often used for fallback values, but it also replaces valid falsy values such as zero, empty strings and empty collections. Use an explicit None check when only missing values should trigger the fallback. Exceptions in evaluated operands are not suppressed.

Formal Syntax & Structure

python syntaxpython
left or right

Parameters & Attributes

NameTypeDescription
leftobjectFirst operand; truth tested.
rightexpressionEvaluated only when the left operand is falsy.

Return Value

object

The left operand if truthy, otherwise the evaluated right operand.

Working Example

Example Snippetpython
label = ""print(label or "untitled")print(0 or 10)print("ready" or 1 / 0)
Python Reference