---
title: Logical Operators in Python
source: https://app.sythra.ai/learn/python/logical-operators
topic: Python
updated: 2026-08-06
publisher: Sythra (https://app.sythra.ai)
---

# Logical Operators in Python

Logical operators in Python — and, or, not — explained with clear examples, truth tables, short-circuiting, and common mistakes.

_Source: [https://app.sythra.ai/learn/python/logical-operators](https://app.sythra.ai/learn/python/logical-operators) — free to read on Sythra._

## Key points

- and returns True only if both sides are true
- or returns True if at least one side is true
- not inverts a boolean value
- Python short-circuits — it stops evaluating once the result is known
- Non-boolean values are treated with truthiness rules

## Intuition with a real example

Imagine a login check: the user may enter only if they have a valid password and their account is active. That is and. A discount may apply if someone is a student or a senior — that is or. A feature that is hidden when a flag is off uses not.

- Door opens only if key works AND alarm is off → and
- Alarm triggers if window OR door is open → or
- Show tip when NOT dismissed → not

## The three operators

Here is the core mental model. Memorize the truth behavior first; short-circuiting and return values come next.

- x and y → True only when both x and y are true
- x or y → True when at least one of x or y is true
- not x → True when x is false

## Truth table (quick reference)

For booleans, the outcomes are fixed. Keep this table nearby until it feels automatic.

- True and True → True | True and False → False
- False and True → False | False and False → False
- True or True → True | True or False → True
- False or True → True | False or False → False
- not True → False | not False → True

## Short-circuiting

Python is lazy in a useful way. With and, if the left side is already false, the right side never runs. With or, if the left side is already true, the right side never runs.

That matters when the right side is expensive or unsafe — for example, checking that a value exists before reading an attribute.

```python
user = {"name": "Ada"}

# Right side runs only if user is truthy
if user and user.get("name"):
    print(user["name"])
```

## Python implementation

A small runnable example showing and, or, and not in conditions you will actually write.

```python
age = 20
has_id = True
is_banned = False

can_enter = age >= 18 and has_id and not is_banned
is_weekend_or_holiday = False or True

print(can_enter)            # True
print(is_weekend_or_holiday)  # True
print(not has_id)           # False

# Truthiness: and/or return an operand
print("" or "fallback")    # fallback
print("hello" and "world")  # world
```

## When to use them

- Guarding if-statements and while-loops
- Combining validation rules (email present and password long enough)
- Feature flags and permissions (role is admin or owner)
- Filtering lists with comprehensions

## Advantages and limitations

Logical operators are simple, readable, and everywhere in Python. The main traps are confusing them with bitwise operators, forgetting parentheses in mixed expressions, and misunderstanding that and/or return values — not always True/False.

- Advantage: clear intent in conditions
- Advantage: short-circuiting avoids unnecessary work
- Limitation: long chains get hard to read — extract named booleans
- Limitation: mixing and/or without parentheses invites bugs

## Common mistakes

- Writing if x == 1 or 2: — this is always truthy; use if x in (1, 2):
- Using & / | instead of and / or in regular if-conditions
- Assuming and always returns True or False (it may return an operand)
- Skipping parentheses in a and b or c — group intentionally

## FAQ

### What are the logical operators in Python?

Python has three logical operators: and, or, and not. They combine or invert boolean conditions in expressions and if-statements.

### What is short-circuit evaluation?

Python stops evaluating a logical expression as soon as the result is decided. For and, if the left side is false, the right side is skipped. For or, if the left side is true, the right side is skipped.

### Can I use and/or with numbers and strings?

Yes. Python uses truthiness: 0, empty strings, empty lists, and None are falsy. and/or return one of the operands, not always True/False.

### What's the difference between & and and?

and is the logical operator for conditions. & is a bitwise operator (and also used with some libraries like pandas). For if-conditions, use and.

## Related

- [Programs, Interpreters & Compilers](https://app.sythra.ai/learn/python/programs-interpreters-compilers) — What a program is, and how interpreters vs compilers run your code.
- [Types, Values, and Errors in Python](https://app.sythra.ai/learn/python/types-values-errors) — int, float, str, type(), and the three kinds of errors.
- [Operators and Operands in Python](https://app.sythra.ai/learn/python/operators-operands) — How values interact — arithmetic, comparison, assignment, and more.
- [Variables in Python](https://app.sythra.ai/learn/python/variables) — Assignment, naming, updates, and snake_case conventions.
- [Comparison Operators in Python](https://app.sythra.ai/learn/python) — ==, !=, <, > — how Python compares values before logic kicks in.
- [If Statements in Python](https://app.sythra.ai/learn/python) — Turn boolean results into decisions with if, elif, and else.
- [Booleans and Truthiness](https://app.sythra.ai/learn/python) — Why empty strings and 0 behave as false in conditions.
- [Python course hub](https://app.sythra.ai/learn/python) — All free Python explainers and the path into Agentic practice.

---

Written by Sythra — Learn machine learning by building. Practice this topic with Sythra's AI tutor: https://app.sythra.ai/pricing
