✍️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 Installation & First Program
Comments
Post a Comment