Types of Operators in Python: A Beginner’s Guide
By Rohit Sharma
Updated on Oct 09, 2025 | 16 min read | 8.33K+ views
Share:
For working professionals
For fresh graduates
More
By Rohit Sharma
Updated on Oct 09, 2025 | 16 min read | 8.33K+ views
Share:
Table of Contents
| Did you know? With 92% of data professionals and 80% of AI developers preferring Python for its simplicity and efficiency, it’s the top choice for many industries. Python plays a central role in data science, AI, machine learning, automation, web development, finance, and scientific computing. |
Python provides a variety of operators to perform different operations on values and variables. These include arithmetic operators for calculations, relational operators for comparisons, logical operators to combine conditions, and assignment operators to update values. Python also offers bitwise, identity, and membership operators for specific tasks. Learning these types of operators helps you write precise and efficient code.
In this guide, you'll read more about the main types of operators in Python. We'll cover arithmetic, relational, logical, and assignment operators in detail. You’ll also explore bitwise, identity, and membership operators, along with operator precedence. Examples, tables, and charts are included to make these concepts easy to understand and apply in your programs.
Looking to sharpen your Python programming skills further? Explore upGrad’s Software Engineering courses, designed with hands-on projects and mentorship to help you master core concepts like operators in Python, control flow, and beyond. Enroll today!
Let’s take a quick overview of types of operators in Python. After we will explore all types in detail.
Popular Data Science Programs
Operator Type |
Purpose |
Common Operators |
Example |
| Arithmetic | Perform mathematical operations | +, -, *, /, %, //, ** | 5 + 3 = 8 |
| Relational / Comparison | Compare values, return True/False | ==, !=, >, <, >=, <= | 5 > 3 → True |
| Logical | Combine conditional statements | and, or, not | True and False → False |
| Assignment | Assign or update variable values | =, +=, -=, *=, /=, %= | x += 2 |
| Bitwise | Operate on binary representations | &, ` | , ^, ~, <<, >>` |
| Identity | Check if objects occupy the same memory | is, is not | a is b → False |
| Membership | Test if a value exists in a sequence | in, not in | 3 in [1,2,3] → True |
Arithmetic operators are the most familiar category for anyone who has taken a math class. These are the tools you use to perform basic mathematical calculations like addition, subtraction, multiplication, and division. They form the bedrock of numerical computation in Python.
In Python, these operators work as you would expect with numbers (integers and floats). Let's explore each one with simple examples. Assume we have two variables for our examples: a = 13 and b = 5.
| Operator | Name | Description | Example (a=13, b=5) |
| + | Addition | Adds two operands | a + b results in 18 |
| - | Subtraction | Subtracts the right operand from the left | a - b results in 8 |
| * | Multiplication | Multiplies two operands | a * b results in 65 |
| / | Division | Divides the left operand by the right | a / b results in 2.6 |
| % | Modulus | Returns the remainder of the division | a % b results in 3 |
| ** | Exponentiation | Raises the left operand to the power of the right | a ** b results in 371293 |
| // | Floor Division | Performs division and rounds down to the nearest integer | a // b results in 2 |
Let's see these operators at work in Python code.
Addition, Subtraction, and Multiplication
These are the most straightforward operators.
Python
a = 13
b = 5
print(f"Addition: {a + b}")
print(f"Subtraction: {a - b}")
print(f"Multiplication: {a * b}")
Output:
Addition: 18
Subtraction: 8
Multiplication: 65
Division vs. Floor Division
It's important to see the difference between these two. Standard division (/) always returns a floating-point number. Floor division (//) returns an integer by discarding the decimal part.
Python
a = 13
b = 5
print(f"Standard Division: {a / b}")
print(f"Floor Division: {a // b}")
Output:
Standard Division: 2.6
Floor Division: 2
Modulus and Exponentiation
The modulus operator is incredibly useful for tasks like checking if a number is even or odd. Exponentiation is for calculating powers.
Python
a = 13
b = 5
print(f"Modulus (Remainder): {a % b}")
print(f"Exponentiation (Power): {2 ** 3}") # 2 to the power of 3
Output:
Modulus (Remainder): 3
Exponentiation (Power): 8
Understanding these arithmetic operators is a critical first step in mastering the different types of operators in Python.
Also Read: Step-by-Step Guide to Learning Python for Data Science
Data Science Courses to upskill
Explore Data Science Courses for Career Progression
The next major category is the assignment operator in Python. These operators are used to assign or update the value of a variable. The most basic assignment operator is the equals sign (=), which you've already seen. It simply stores the value on the right in the variable on the left.
Beyond the simple equals sign, Python provides several compound assignment operators. These are convenient shorthands that combine an arithmetic operation with an assignment. For example, instead of writing x = x + 10, you can simply write x += 10. This makes your code cleaner and more concise.
Let's look at the primary assignment operators.
| Operator | Example | Equivalent To |
| = | x = 10 | x = 10 |
| += | x += 5 | x = x + 5 |
| -= | x -= 5 | x = x - 5 |
| *= | x *= 5 | x = x * 5 |
| /= | x /= 5 | x = x / 5 |
| %= | x %= 3 | x = x % 3 |
| **= | x **= 2 | x = x ** 2 |
| //= | x //= 3 | x = x // 3 |
Here’s how you would use these operators in a real script. We'll initialize a variable and then update it using different compound operators.
Python
# Start with a base value
score = 100
print(f"Initial score: {score}")
# Add points
score += 20
print(f"Score after adding 20: {score}")
# Subtract points
score -= 10
print(f"Score after subtracting 10: {score}")
# Double the score
score *= 2
print(f"Score after multiplying by 2: {score}")
# Halve the score
score /= 2
print(f"Score after dividing by 2: {score}")
Output:
Initial score: 100
Score after adding 20: 120
Score after subtracting 10: 110
Score after multiplying by 2: 220
Score after dividing by 2: 110.0
Notice that using the /= operator converted our score variable from an integer to a float. This is an important behavior to remember. Mastering the assignment operator in Python is key to managing state within your programs.
Also Read: Top 36+ Python Projects for Beginners and Students to Explore in 2025
Comparison operators, also known as relational operators, are used to compare two values. The result of a comparison is always a Boolean value, which is either True or False. These operators are the heart of decision-making in programming. You use them constantly in if statements and while loops to control your program's flow.
Understanding these operators is essential for writing code that can react differently to different inputs. Let's review the six main comparison operators.
| Operator | Name | Description | Example (a=10, b=20) |
| == | Equal to | Returns True if both operands are equal | a == b is False |
| != | Not equal to | Returns True if operands are not equal | a != b is True |
| > | Greater than | Returns True if the left operand is greater | a > b is False |
| < | Less than | Returns True if the left operand is smaller | a < b is True |
| >= | Greater than or equal to | Returns True if the left operand is greater than or equal to the right | a >= b is False |
| <= | Less than or equal to | Returns True if the left operand is less than or equal to the right | a <= b is True |
Let's see how Python evaluates expressions using these operators.
Python
a = 10
b = 20
c = 10
# Equal to and Not equal to
print(f"Is a equal to b? {a == b}")
print(f"Is a equal to c? {a == c}")
print(f"Is a not equal to b? {a != b}")
# Greater than and Less than
print(f"Is a greater than b? {a > b}")
print(f"Is b less than or equal to 20? {b <= 20}")
Output:
Is a equal to b? False
Is a equal to c? True
Is a not equal to b? True
Is a greater than b? False
Is b less than or equal to 20? True
These True and False values are what allow you to create logic, for example:
Python
age = 25
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
This is a practical demonstration of why comparison operators are a fundamental part of the types of operators in Python.
Also Read: Understanding Python Data Types
Logical operators are used to combine conditional statements. They allow you to check multiple conditions at the same time. This is incredibly powerful for creating complex decision-making logic. There are three logical operators in Python: and, or, and not.
Let's look at their truth tables.
and Operator
A |
B |
A and B |
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
or Operator
A |
B |
A or B |
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |
Here's how you might use these operators to check for application eligibility.
Python
age = 22
has_good_credit = True
# Using the 'and' operator
if age >= 18 and has_good_credit:
print("Application for loan approved.")
else:
print("Application for loan denied.")
# Using the 'or' operator
is_weekend = True
has_holiday_pass = False
if is_weekend or has_holiday_pass:
print("You get a discount on your ticket!")
else:
print("No discount applicable.")
# Using the 'not' operator
is_logged_in = False
if not is_logged_in:
print("Please log in to see your profile.")
Output:
Application for loan approved.
You get a discount on your ticket!
Please log in to see your profile.
Logical operators are the glue that holds your program's logic together, making them one of the most important types of operators in Python to master.
Also Read: Data Science for Beginners: Prerequisites, Learning Path, Career Opportunities and More
Beyond the common operators, Python has several specialized sets for more advanced or specific tasks. While you may not use these every day as a beginner, knowing they exist is important.
These are very intuitive and useful. Membership operators test whether a value is found within a sequence, like a string, list, or tuple.
Python
my_favorite_fruits = ["apple", "banana", "orange"]
print(f"Is 'banana' a favorite fruit? {'banana' in my_favorite_fruits}")
print(f"Is 'grape' a favorite fruit? {'grape' in my_favorite_fruits}")
print(f"Is 'grape' not a favorite fruit? {'grape' not in my_favorite_fruits}")
Output:
Is 'banana' a favorite fruit? True
Is 'grape' a favorite fruit? False
Is 'grape' not a favorite fruit? True
Identity operators compare the memory location of two objects, not just their values. This is a subtle but critical difference from the == operator.
Python
x = ["apple", "banana"]
y = ["apple", "banana"]
z = x
# '==' checks for equality of values
print(f"Does x equal y? {x == y}")
# 'is' checks for identity (same object in memory)
print(f"Is x the same object as y? {x is y}")
print(f"Is x the same object as z? {x is z}")
Output:
Does x equal y? True
Is x the same object as y? False
Is x the same object as z? True
Bitwise operators act on operands at the binary level. They are used in lower-level programming, networking, and cryptography. As a beginner, you only need to be aware of them. The main ones are & (AND), | (OR), ^ (XOR), and ~ (NOT).
Also Read: Comprehensive Guide to Binary Code: Basics, Uses, and Practical Examples
When you have multiple operators in a single expression, how does Python know which one to perform first? It follows a set of rules called operator precedence. This is similar to the PEMDAS/BODMAS rule you learned in math class (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction).
Understanding the precedence of operators in Python is crucial for writing correct and bug-free code. An expression like 10 + 5 * 2 is not evaluated left-to-right. Python knows that multiplication has higher precedence than addition, so it calculates 5 * 2 first, and then adds 10 to get 20.
The table below shows the order of precedence for the most common operators, from highest to lowest.
| Precedence | Operator | Description |
| Highest | () | Parentheses |
| ** | Exponentiation | |
| *, /, //, % | Multiplication, Division, Floor Division, Modulus | |
| +, - | Addition and Subtraction | |
| in, is | Membership and Identity | |
| <, <=, >, >= | Comparison operators | |
| ==, != | Equality operators | |
| not, and, or | Logical operators | |
| Lowest | = | Assignment operator |
Let's see how precedence affects the outcome of an expression.
Python
# Without parentheses
result1 = 10 + 5 * 2
# Python evaluates 5 * 2 first, then 10 + 10
print(f"Result 1 (10 + 5 * 2): {result1}")
# With parentheses
result2 = (10 + 5) * 2
# The parentheses force the addition to be evaluated first
print(f"Result 2 ((10 + 5) * 2): {result2}")
# Complex example
result3 = 100 / 5 + 3 * 2 ** 2
# 1. Exponent: 2 ** 2 = 4
# 2. Division/Multiplication: 100 / 5 = 20.0 and 3 * 4 = 12
# 3. Addition: 20.0 + 12 = 32.0
print(f"Result 3: {result3}")
Output:
Result 1 (10 + 5 * 2): 20
Result 2 ((10 + 5) * 2): 30
Result 3: 32.0
When in doubt, always use parentheses () to make the order of operations explicit. It makes your code easier to read and guarantees it will be evaluated correctly. This is a key skill when working with the different types of operators in Python.
Mastering operators is non-negotiable for any aspiring Python developer. They are the core syntax that allows you to manipulate data, control program flow, and implement logic. From the simple addition of two numbers to combining complex conditional checks, every line of functional code you write will rely on them.
In this guide, we have explored all the major types of operators in Python, including Arithmetic, Assignment, Comparison, Logical, and more specialized ones. We also demystified the precedence of operators in Python, giving you the knowledge to write predictable and accurate code. By practicing with these fundamental tools, you are building a solid foundation for your entire programming journey.
Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
Unlock the power of data with our popular Data Science courses, designed to make you proficient in analytics, machine learning, and big data!
Elevate your career by learning essential Data Science skills such as statistical modeling, big data processing, predictive analytics, and SQL!
Stay informed and inspired with our popular Data Science articles, offering expert insights, trends, and practical tips for aspiring data professionals!
Python offers several types of operators, including arithmetic, relational, logical, assignment, bitwise, identity, and membership operators. Each type serves a specific purpose, allowing you to perform calculations, comparisons, logical operations, and value assignments efficiently in your programs.
Knowing the types of operators in Python helps you write accurate code, avoid errors, and improve program efficiency. It ensures you select the correct operator for tasks like math calculations, condition checking, or updating variables, making your code more readable and maintainable.
Arithmetic operators in Python perform mathematical operations. They include + (addition), - (subtraction), * (multiplication), / (division), % (modulus), // (floor division), and ** (exponent). These operators are a fundamental part of the types of operators in Python.
Relational operators compare two values and return True or False. Examples include ==, !=, >, <, >=, and <=. They are essential among the types of operators in Python for decision-making and controlling program flow.
Logical operators in Python combine multiple conditions. The main logical operators are and, or, and not. They allow you to evaluate complex expressions, making them a key part of the types of operators in Python.
The assignment operator in Python is =. It assigns a value to a variable. Python also supports compound assignment operators like +=, -=, *=, /=, and %=. Understanding the assignment operator in Python is crucial for updating variables efficiently.
Bitwise operators in Python manipulate binary representations of integers. Operators include &, |, ^, ~, <<, and >>. They are part of the types of operators in Python and are useful for low-level computations and efficient data handling.
Identity operators (is, is not) check if two objects occupy the same memory location. They differ from equality operators (==) and are considered one of the advanced types of operators in Python.
Membership operators (in, not in) test if a value exists within a sequence like a list, tuple, or string. They are another type of operator in Python that simplifies checking collection membership.
Operator precedence in Python determines the order in which operators are evaluated in expressions. For example, ** (exponent) has higher precedence than + or -. Understanding precedence of operators in Python avoids unexpected results.
Operator associativity in Python defines the direction of evaluation when multiple operators of the same precedence appear. Most operators associate left-to-right, except exponentiation (**), which is right-to-left. This affects the precedence of operators in Python.
You can combine arithmetic, relational, logical, and assignment operators in a single expression. Understanding the types of operators in Python and their precedence ensures correct evaluation and prevents logical errors in code.
Yes, compound assignment operators like +=, -=, *=, and /= combine assignment and arithmetic operations. They make code shorter and more readable while demonstrating the role of the assignment operator in Python.
Common mistakes include ignoring operator precedence, mixing incompatible types, or using = instead of == in comparisons. Awareness of types of operators in Python helps prevent these errors.
Relational operators compare values, while logical operators combine Boolean results of multiple relational expressions. Both are key types of operators in Python, but they serve distinct purposes in decision-making.
Arithmetic operators work on numerical values, while bitwise operators manipulate binary representations of integers. Both are types of operators in Python, but bitwise operators are typically used for low-level operations.
The assignment operator in Python is fundamental for storing and updating values. Beginners need to master it to manipulate variables correctly and understand how other types of operators interact with variable assignments.
Yes. Operator precedence in Python ensures that higher-priority operations, like arithmetic, execute before lower-priority operations, like logical comparisons, avoiding unexpected results in expressions.
Practice with examples, use tables, and refer to Python documentation. Understanding the types of operators in Python and their precedence makes coding more predictable and reduces errors.
Official Python documentation, tutorials, and educational blogs like upGrad provide detailed explanations, examples, and practice exercises to master the types of operators in Python, assignment operator in Python, and operator precedence.
834 articles published
Rohit Sharma is the Head of Revenue & Programs (International), with over 8 years of experience in business analytics, EdTech, and program management. He holds an M.Tech from IIT Delhi and specializes...
Speak with Data Science Expert
By submitting, I accept the T&C and
Privacy Policy
Start Your Career in Data Science Today
Top Resources