> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Logical OR

The `or` operator in Python is a logical operator that performs inclusive disjunction. It evaluates two expressions and returns the first operand if it resolves to a truthy value; otherwise, it evaluates and returns the second operand. Unlike some languages where logical operators strictly return boolean types (`True` or `False`), Python's `or` operator returns the actual object reference of the evaluated operand.

```python theme={"dark"}
operand_left or operand_right
```

## Evaluation Mechanics

Python evaluates the `or` operator using **short-circuit evaluation**. The interpreter processes the operands from left to right based on their boolean context (truthiness).

1. `operand_left` is evaluated.
2. If `operand_left` is truthy, the expression immediately returns `operand_left`. The `operand_right` expression is completely ignored (short-circuited).
3. If `operand_left` is falsy, the interpreter evaluates and returns `operand_right`.

## Truthiness and Return Values

In Python, objects like `None`, `0`, `0.0`, empty sequences (`""`, `[]`, `()`), and empty mappings (`{}`) are considered **falsy**. All other objects are generally considered **truthy**.

```python theme={"dark"}

# Standard boolean evaluation
True or False        # Evaluates to: True


# First operand is truthy: Returns the first operand
"Python" or ""       # Evaluates to: "Python"
[1, 2] or [3, 4]     # Evaluates to: [1, 2]
10 or 0              # Evaluates to: 10


# First operand is falsy: Returns the second operand
0 or 20              # Evaluates to: 20
"" or "String"       # Evaluates to: "String"
None or []           # Evaluates to: []


# Both operands are falsy: Returns the second operand
0 or False           # Evaluates to: False
"" or 0              # Evaluates to: 0
```

## Short-Circuit Demonstration

Because of short-circuiting, the right-hand operand is only executed if the left-hand operand is falsy. This is observable when the right-hand operand contains a function call or an operation with side effects.

```python theme={"dark"}
def side_effect():
    print("Evaluated!")
    return True


# side_effect() is NOT called because 1 is truthy
result_1 = 1 or side_effect() 

# result_1 is 1


# side_effect() IS called because 0 is falsy
result_2 = 0 or side_effect() 

# Prints: "Evaluated!"

# result_2 is True
```

## Chaining Multiple `or` Operators

When multiple `or` operators are chained, the interpreter evaluates from left to right and stops at the very first truthy operand it encounters, returning that operand. If no truthy operand is found, it returns the final falsy operand.

```python theme={"dark"}

# Stops at 5 (first truthy value)
result = 0 or [] or 5 or "String"  # Evaluates to: 5


# Evaluates all, returns the last falsy value
result = 0 or [] or "" or None     # Evaluates to: None
```

## Operator Precedence

The `or` operator has the lowest precedence among Python's logical operators (`not`, `and`, `or`). It evaluates after `and` but before assignment operators.

```python theme={"dark"}

# 'and' is evaluated before 'or'

# Equivalent to: "A" or ("" and "B") -> "A" or "" -> "A"
"A" or "" and "B"    # Evaluates to: "A"


# Equivalent to: ("" or "A") and "B" -> "A" and "B" -> "B"
("" or "A") and "B"  # Evaluates to: "B"
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
