Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator or

Returns the first truthy operand or the last operand reached.

Version: Python 3.14; repository image, production runtime not attested

Syntax

left or right

Returns the first truthy operand or the last operand reached.

Use a fallback expression when every falsy value should trigger the default. Both an empty string and numeric zero cause evaluation to continue to the right.

When zero is a meaningful stored value, test specifically for a missing sentinel before supplying a default. The operator forwards an operand rather than converting it to Boolean.

The right expression is skipped when the left operand already tests true.

Syntax

left or right

__bool__, __len__ · left or right

Worked example

4 or 1 / 0 → 4
0 or "guest" → "guest"

Examples

print("" or "guest")
print(8 or 1 / 0)

Result

guest
8

The right expression is skipped when the left operand already tests true.

Sources