Skip to main content

Python Operators: Types with Examples

 ✍️Introduction

In Python, operators are symbols used to perform operations on variables and values.

Operators help us do calculations, comparisons, and logical decisions in programs.

In this article, you will learn:


• What Python operators are

• Types of Python operators

• Simple examples for each type

What are Python Operators?

Python operators are special symbols that tell Python to perform a specific operation.


Example:

a = 10

b = 5

print(a + b)

Here, + is an operator.

🔢 Types of Python Operators

Python operators are mainly divided into 7 types:


1. Arithmetic Operators

2. Comparison Operators

3. Logical Operators

4. Assignment Operators

5. Bitwise Operators

6. Membership Operators

7. Identity Operators

1️⃣ Arithmetic Operators

Used for mathematical calculations.

Operator            Meaning                Example 


+                        Addition                     a + b 

-                        Subtraction                 a - b 

*                       Multiplication            a * b 

/                        Division                       a / b 

%                     Modulus                       a % b 

**                    Exponent                      a ** b 

//                      Floor Division             a // b 


Example:

a = 10

b = 3

print(a + b)

print(a % b)

2️⃣ Comparison Operators

Used to compare two values.

Result is always True or False.

   Operator                               Meaning 


        ==                                         Equal to 

        !=                                          Not equal 

        >                                          Greater than 

       <                                          Less than 

       >=                              Greater than or equal

      <=                                     Less than or equal 

Example:

a = 10

b = 5

print(a > b)

3️⃣ Logical Operators

Used to combine conditions.

     Operator                          Meaning 


      and                             True if both are true 

     or                                 True if one is true 

      not                               Reverses result 

Example:

x = 5

print(x > 3 and x < 10)

4️⃣ Assignment Operators

Used to assign values to variables.

 Operator              Example             Meaning 


   =                               a = 5                    Assign 

  +=                            a += 3                   a = a + 3 

  -=                             a -= 3                    a = a - 3 

  *=                            a *= 3                    a = a * 3 

  /=                              a /= 3                    a = a / 3 

Example:

a = 10

a += 5

print(a)

5️⃣ Bitwise Operators

Used to work with binary numbers.

     Operator                             Meaning 


          &                                          AND 

          |                                           OR 

         ^                                           XOR 

        ~                                            NOT 

       <<                                        Left shift

        >>                                      Right shift 

Example:

a = 5

b = 3

print(a & b)

6️⃣ Membership Operators

Used to check if a value exists in a sequence.

     Operator                               Meaning 


          in                                        Exists  

        not in                               Does not exist 

Example:

list = [1, 2, 3]

print(2 in list)

7️⃣ Identity Operators

Used to compare memory location of objects.

       Operator                             Meaning


            is                                   Same object 

         is not                             Not same object 

Example:

a = 10

b = 10

print(a is b)

🎯 Why Python Operators are Important?


  • Used in every Python program
  • Help in decision making
  • Important for exams & interviews
  • Make programs powerful and dynamic

Conclusion

Python operators are essential for performing operations in programs.

Understanding operators helps you write efficient and correct Python code.

Practice each operator to become confident in Python programming.

💬 Let’s Interact!


Which operator type do you find most confusing?

Comment below 👇 I’ll explain it with examples 😊


📌 Related Articles:

• Python Keywords

• Python Installation & First Program

• Advantages of Python




Comments

popular

What Is Python Programming? Features, Uses and Career Scope.

  ✍️ Introduction Python is one of the most popular and beginner-friendly programming languages in the world today. It is widely used for web development, data science, artificial intelligence, automation, and software development. Because of its simple syntax and powerful features, Python is an excellent choice for students, beginners, and professionals. In this article, you will learn what Python programming is, its key features, real-life uses, and the career opportunities it offers. 🧠 What Is Python Programming? Python is a high-level, interpreted programming language created to make coding easy and readable. It allows developers to write programs using simple English-like statements, which makes it ideal for beginners. Python supports multiple programming styles such as procedural, object-oriented, and functional programming. ⭐ Features of Python Easy to learn and understand Simple and readable syntax Interpreted language Platform independent Large standard l...

what is Python Date and Time ? Complete Guide with Examples:

  ✍️ Introduction Python provides powerful tools to work with dates and times . The most commonly used module is datetime . The datetime module allows Python programs to create, manipulate, format, and perform calculations with dates and times easily. Date and time handling is used in: Logging systems Attendance & billing systems Data analysis Real-time applications How To Import Date and Time Module : In Python, the datetime module is used to work with dates , times , and date–time combinations . It is part of Python’s standard library, so no installation is required. You can import it in different ways depending on your need. import datetime Get Current Date and Time: This code obtains the current system date and time as a single datetime object using the datetime module. Example: import datetime now = datetime.datetime.now() print (now) Output: 2026-02-13 11:25:53.445827 "Code executed successfully"  Get Only Date: This code retrieves t...

Features of Python Programming Language Explained with Examples

✍️ Introduction Python is one of the most popular programming languages because of its powerful and easy-to-use features. It is designed to make programming simple, readable, and efficient. Python is widely used by beginners as well as professionals due to its flexibility and strong community support. In this article, we will discuss the main features of Python programming language in simple English with easy examples. 🧠 What Are Features of Python? Features of Python are the special characteristics that make it different from other programming languages. These features help programmers write clean, readable, and efficient code with less effort. ⭐ Key Features of Python Programming Language 1️⃣ Easy to Learn and Easy to Use Python has a simple syntax that is close to the English language. This makes it very easy for beginners to learn and understand programming concepts. Example: print("Hello, World!") 2️⃣ Interpreted Language Python is an interpreted language, which me...