Skip to main content

What are operators?

Operators are symbols that perform operations on values. Think of them as the “verbs” of programming - they make things happen! You already know most operators from math class:
  • Calculate: +, -, *, /
  • Compare: >, <, ==
  • Combine: and, or, not

Arithmetic operators

These work just like your calculator:

Order of operations

Python follows math rules (PEMDAS):

Comparison operators

These compare values and return True or False:
Don’t confuse = (assignment) with == (comparison)!
  • age = 18 stores 18 in age
  • age == 18 checks if age equals 18

Logical operators

These combine boolean values and conditions:

Truth tables

Understanding how and, or, and not work:

Short-Circuit Evaluation & Non-Booleans

In Python, logical operators (and, or) do not just return True or False. They return one of the actual evaluated values. Python evaluates values in a boolean context as either truthy or falsy:
  • Falsy values: False, None (Python’s null value), 0, 0.0, empty strings "", and empty lists/dictionaries.
  • Truthy values: Almost everything else (non-zero numbers, non-empty strings/lists).

How and behaves (Short-Circuit):

The and operator evaluates expressions from left to right and returns the first falsy value it encounters. If all values are truthy, it returns the last evaluated value.

How or behaves (Short-Circuit):

The or operator evaluates from left to right and returns the first truthy value it encounters. If all values are falsy, it returns the last evaluated value.

Assignment shortcuts

These shortcuts update variables in place:

Common mistakes

Practice & Exercises

To reinforce what you’ve learned in this section (Arithmetic, Comparison, and Logical Operators), practice with these interactive notebooks:

Follow-Along Practice

Practice operators, PEMDAS rules, logical evaluations, and assignment shortcuts.💻 VS Code | 🚀 Colab | 📥 Download

Practice Exercises

Test your knowledge with hands-on exercises on floor division vs modulo, order of operations, and logical conditions.💻 VS Code | 🚀 Colab | 📥 Download

What’s next?

Once you are comfortable with Operators, let’s learn how to manipulate text strings!

String manipulation

Advanced text operations