Mastering Python Operators:
Arithmetic, Relational, Logical, and
Bitwise Logic
An In-Depth Academic and Practical Exploration of Expression Evaluation in Python
Author: Python Core Development Series
Publication Year: 2026
Focus: Complete Operators Reference, Precedence, and Associativity
Mastering Python Operators Page 1
Table of Contents
Chapter 1: Introduction to Operators and Expressions in Python
Chapter 2: Arithmetic and Assignment Operators
Chapter 3: Relational (Comparison) and Logical Operators
Chapter 4: Bitwise, Identity, and Membership Operators
Chapter 5: Operator Precedence, Associativity, and Complex Expressions
Mastering Python Operators Page 2
Chapter 1: Introduction to Operators and Expressions
In programming languages, operators are special symbols or keywords that carry out operations on
values and variables. These values and variables are referred to as operands. When operators and
operands are combined according to the syntax rules of Python, they form expressions, which the
interpreter evaluates to produce new values.
1.1 Classification of Operators
Python categorizes operators into several distinct functional groups based on the nature of the
computation they execute:
• Arithmetic Operators: Used to perform mathematical calculations like addition, subtraction,
multiplication, and division.
• Relational (Comparison) Operators: Used to compare values and return boolean outcomes
(True or False).
• Logical Operators: Used to combine conditional statements using boolean algebra (and, or, not).
• Bitwise Operators: Used to perform operations on individual binary bits of integer operands.
• Assignment Operators: Used to assign values to variables, often combined with arithmetic
modifications.
• Identity Operators: Used to compare memory addresses and check if two variables point to the
exact same object (is, is not).
• Membership Operators: Used to test whether a value is present within a sequence such as a list,
tuple, or string (in, not in).
Chapter 2: Arithmetic and Assignment Operators
Arithmetic operators form the bedrock of numerical data processing in Python. They follow standard
mathematical conventions while introducing special operators for computer science applications.
Mastering Python Operators Page 3
2.1 Comprehensive Arithmetic Operators Table
Example (a = 10,
Operator Name Description Result
b = 3)
+ Addition Adds two operands. a + b 13
- Subtraction Subtracts right operand from left. a - b 7
* Multiplication Multiplies two operands. a * b 30
Divides left by right (always
/ Division a / b 3.3333...
returns float).
Divides and rounds down to
// Floor Division a // b 3
nearest integer.
% Modulus Returns remainder of division. a % b 1
Raises left operand to power of
** Exponentiation a ** b 1000
right.
2.2 Compound Assignment Operators
Assignment operators are used to assign values to variables. Python also provides shorthand
compound assignment operators that combine an arithmetic operation with assignment:
x = 5 # Basic assignment
x += 3 # Equivalent to: x = x + 3 (x becomes 8)
x *= 2 # Equivalent to: x = x * 2 (x becomes 16)
x //= 4 # Equivalent to: x = x // 4 (x becomes 4)
Mastering Python Operators Page 4
Chapter 3: Relational and Logical Operators
Decision making in software requires comparing values and combining multiple criteria. Relational and
logical operators evaluate conditions to yield boolean results (True or False).
3.1 Relational (Comparison) Operators
Relational operators evaluate the relationship between two operands:
• Equal to (==): Returns True if operands are equal.
• Not equal to (!=): Returns True if operands are not equal.
• Greater than (>) & Less than (<).
• Greater than or equal to (>=) & Less than or equal to (<=).
3.2 Logical Operators and Short-Circuit Evaluation
Logical operators (and, or, not) manage compound conditions:
is_active = True
has_permission = False
print(is_active and has_permission) # Output: False
print(is_active or has_permission) # Output: True
print(not is_active) # Output: False
Performance Tip: Python utilizes short-circuit evaluation for logical operations. In an and
expression, if the left operand is false, Python skips evaluating the right operand. In an or
expression, if the left operand is true, the right operand is skipped.
Mastering Python Operators Page 5
Chapter 4: Bitwise, Identity, and Membership Operators
Advanced Python programming frequently leverages bitwise manipulations, object identity checks, and
collection membership tests.
4.1 Bitwise Operators
Bitwise operators operate on integers at the binary level, treating numbers as sequences of bits:
• Bitwise AND (&), OR (|), XOR (^), and NOT (~).
• Bitwise Shift: Left shift (<<) and Right shift (>>).
4.2 Identity and Membership Operators
Identity operators (is, is not) check whether two variables share an identical memory location.
Membership operators (in, not in) verify element presence inside collections.
fruits = ["apple", "banana", "cherry"]
print("banana" in fruits) # Output: True
print("grape" not in fruits) # Output: True
Chapter 5: Operator Precedence and Associativity
When an expression contains multiple operators, Python evaluates them according to strict precedence
rules. Operations with higher precedence are evaluated before lower precedence operators.
Mastering Python Operators Page 6
5.1 Precedence Hierarchy Table
Precedence Order Operator Type Operators
1 (Highest) Parentheses ( )
2 Exponentiation **
3 Unary Plus, Minus, Bitwise NOT +x, -x, ~x
4 Arithmetic Mult/Div *, /, //, %
5 Arithmetic Add/Sub +, -
6 Bitwise Shifts <<, >>
7 Bitwise AND, XOR, OR &, ^, |
8 Comparisons & Identity/Membership ==, !=, >, <, is, in
9 Logical NOT, AND, OR not, and, or
Mastering operators ensures that complex expressions and boolean logic execute accurately, providing
a robust backbone for clean, optimized software engineering.
Mastering Python Operators Page 7