Python Operators Explained

Learn what Python operators are, the seven categories they fall into, and how each group helps you write calculations, comparisons, assignments, and logic.

5 min read

Python operators are the symbols and keywords that tell the computer what to do with the values you provide. When you write an addition expression with the plus sign between two numbers, the plus sign is an operator, the numbers are its operands, and Python computes the result. Without operators, your variables and data types would sit idle because there would be no way to add numbers together, compare two strings, check whether a value belongs to a list, or combine multiple conditions into a single decision. Operators turn passive data into active computation, and every Python program you write from this point forward will use them on nearly every line.

Python organizes its operators into seven categories, and the first five cover the vast majority of what a beginner needs. Arithmetic operators handle math with symbols for addition, subtraction, multiplication, and more. Assignment operators store values and update them with shorthand forms that combine calculation and storage in one step. Comparison operators test relationships like equality, inequality, and ordering, always producing a True or False result. Logical operators combine boolean conditions using the keywords and, or, and not, and they control how your program decides which branch of code to execute. The remaining two categories, identity operators with is and is not, and membership operators with in and not in, appear in specific situations like checking whether two variables point to the same object or whether a value lives inside a collection. Bitwise operators work at the level of individual bits and are less common in beginner programs.

This article gives you the map. Each category gets its own dedicated article in the pages that follow. You do not need to memorize every operator at once. The goal is to recognize what each group does so you can reach for the right tool when your program needs it.

What an operator does

An operator takes one or more values, called operands, and produces a new value as its result. The addition operator takes two operands and returns their sum. The subtraction operator takes two operands and returns their difference. The unary minus, written as a single dash before a value like -5, takes only one operand and negates it. Most Python operators are binary, meaning they sit between two operands, but a few like unary minus and the logical not are unary and work with a single operand.

An expression is any valid combination of operators and operands that Python can evaluate to a single value. When you write a short calculation like 2 + 3 * 4, the expression contains two operators and three operands, and Python evaluates it to 14 because multiplication takes priority over addition. Understanding which operator runs first is the subject of operator precedence, a later article in this section that ties everything together after you have learned each category individually.

pythonpython
# Operators take operands and produce values
result = 2 + 3 * 4
print(result)        # 14

Operators are not just for numbers. When you use plus between two strings, Python concatenates them. When you use it between two lists, Python joins the lists together. The multiplication operator repeats a string or list when one side is an integer. The in keyword checks whether a substring appears inside a larger string or whether a value exists inside a list, tuple, set, or dictionary. This reuse of operators across data types is a deliberate design choice in Python that keeps the language consistent. Once you learn what plus does, you can apply that understanding to strings, lists, and tuples without learning a separate syntax for each type.

The seven operator categories

Python groups its operators by what they do, not by what types they work with. The seven categories are listed below in the order a beginner typically encounters them.

Arithmetic operators perform mathematical calculations. You will use addition, subtraction, multiplication, division that always returns a float, floor division that discards the remainder, modulo that returns the remainder, and exponentiation for powers. These operators work on integers, floats, and complex numbers, and several of them also work on sequences like strings and lists. The article on arithmetic operators in Python covers each one with runnable examples.

Assignment operators bind values to variable names. The basic assignment uses a single equals sign, but Python also provides compound assignment operators that add-and-assign, subtract-and-assign, and similar shortcuts for every arithmetic and bitwise operator. These compound operators make your code shorter and clearer because they signal that you are updating an existing value rather than creating a new one.

Comparison operators test the relationship between two values and always return a boolean result. The equality operator checks whether two values are the same, the inequality operator checks whether they differ, and the less-than and greater-than family test ordering. Python supports chained comparisons that read like mathematical inequalities and evaluate multiple conditions together. The article on comparison operators in Python shows how to use each one and how chaining works.

Logical operators combine boolean values and control the flow of decision-making in your programs. The and keyword returns True only when both conditions hold. The or keyword returns True when at least one condition holds. The not keyword flips a boolean to its opposite. These operators use short-circuit evaluation, meaning Python stops evaluating as soon as the result is determined, which you can use to write efficient guard conditions.

Identity operators test whether two variables refer to the exact same object in memory. Two lists with the same contents are equal according to the equality operator but are not the same object according to the is operator if they were created separately.

Membership operators test whether a value exists inside a collection. The in keyword returns True when the left operand is found inside the right operand, which can be a string, list, tuple, set, or dictionary. Testing membership in a set or dictionary is extremely fast and does not slow down as the collection grows.

Bitwise operators work on the binary representation of integers. They are less common in everyday beginner code but appear in systems programming, cryptography, and network protocols. A dedicated article later in this section covers them for readers who need them.

Where operators fit in your learning path

You have already used operators without a formal introduction. When you called the print function in the getting-started section, the parentheses triggered the call operator. When you assigned a value to a variable, you used the assignment operator. When you added numbers in the interactive interpreter, you used the addition operator. This section makes that implicit knowledge explicit and fills in the gaps so you can use every operator with confidence.

pythonpython
# You have been using operators from day one
score = 10                    # assignment
score = score + 5             # addition + assignment
print(score)                  # function call (the parentheses)

The natural order is to learn arithmetic operators first because they let you perform calculations. Assignment operators come next because they let you store and update the results. Comparison operators follow because they let you test values, and logical operators complete the set because they let you combine those tests into complex conditions. After that, you will be ready for control flow, where comparison and logical operators drive the if-statements and while-loops that make programs respond to different situations.

Do not skip ahead. Each article in this section builds a specific skill, and the control flow section that comes next depends on your ability to write comparisons and combine them with and and or. Take the time to type the examples into your own editor and experiment with different operand values. The operators are small in number but large in impact, and the fluency you build here will carry through every program you write from this point forward.

Rune AI

Rune AI

Key Insights

  • Python operators are symbols that perform actions on values called operands.
  • The seven operator categories are arithmetic, assignment, comparison, logical, identity, membership, and bitwise.
  • Arithmetic operators handle math; assignment operators store and update values.
  • Comparison operators test relationships between values and return True or False.
  • Logical operators combine boolean conditions so programs can make complex decisions.
  • Identity and membership operators test whether objects are the same or whether a value exists inside a collection.
RunePowered by Rune AI

Frequently Asked Questions

What is an operator in Python?

An operator is a symbol or keyword that tells Python to perform a specific action on one or more values, called operands. For example, the plus sign in 3 + 4 is an operator that adds its two operands and produces the result 7.

How many categories of Python operators are there?

Python has seven operator categories: arithmetic, assignment, comparison, logical, identity, membership, and bitwise. The first five cover the vast majority of beginner and intermediate programming tasks.

Do I need to memorize every operator before moving on?

No. Start with arithmetic and assignment operators because they appear in nearly every program. Comparison and logical operators come next when you reach conditional statements. Identity, membership, and bitwise operators can wait until you encounter specific use cases that need them.

Conclusion

Operators are the verbs of Python. Every calculation, every comparison, and every logical decision flows through them. Learn the categories one at a time, starting with arithmetic and assignment, and you will have the tools to express almost any computation the language can perform.