Skip to main content
Operators are special symbols or keywords in Python that execute specific mathematical, relational, or logical computations on one or more operands. At the language level, Python operators act as syntactic sugar for underlying special methods (often referred to as “dunder” or magic methods) defined on the operand objects.

Arithmetic Operators

Perform standard mathematical operations. They map directly to Python’s numeric protocol methods.

Comparison (Relational) Operators

Evaluate the relationship between two operands, returning a boolean value. Python supports chaining comparison operators, which implicitly applies a logical and between the evaluations.

Logical Operators

Perform boolean logic. Python utilizes short-circuit evaluation for and and or. These operators do not strictly return booleans; they return the last evaluated operand.

Bitwise Operators

Perform bit-level operations on integers. They manipulate the underlying binary representation of the operands.

Assignment Operators

Bind values to variables. Augmented assignment operators combine an arithmetic or bitwise operation with assignment. They attempt to modify the object in-place if the object is mutable.

Identity Operators

Evaluate whether two references point to the exact same object in memory. This is an evaluation of the CPython memory address, distinct from object value equality (==).

Membership Operators

Evaluate whether a specific value exists within a sequence or collection.

The operator Module

Python provides the built-in operator module, which exports a set of efficient, C-implemented functions corresponding to the intrinsic operators. This is utilized primarily in functional programming paradigms where passing an operator as a callable is required.
Tired of Poor Python Skills? Fix That With Deep Grasping!Learn More