Contents
Introduction to Python Operators
Python operators (Digiedutech) are symbols or keywords that let Python perform actions on values and variables. They may look small, but they play a big role in every Python program. Python operators help perform calculations, compare data, make decisions, and control logic in a clean and readable way.
Moreover, python operators make code shorter and easier to read. For example, assignment operators allow you to update values without repeating long expressions. Therefore, learning them early helps you write clean and efficient code.
Additionally, python operators are important when you work with conditions, loops, math operations, and data processing. Consequently, understanding them is a key step toward mastering Python.
Why Python Operators Matter
Python operators are essential because they allow you to:
- Perform calculations smoothly
- Compare values in conditional statements
- Control program logic using logical operators
- Update variables quickly using assignment operators
- Work with binary data, when needed, using bitwise operators
- Check membership and identity, which is useful for collection
Types of Python Operators (Overview)
Python provides several types of operators, each designed for specific kinds of operations. Here’s an overview:
1. Python Arithmetic Operators
Arithmetic operators help you perform basic math in Python. They handle addition, subtraction, multiplication, and division. They also support floor division, modulus, and exponent calculations.
| Sl. No. | Operator | Description | Example |
| 1 | + | Addition | 5 + 3 = 8 |
| 2 | – | Subtraction | 5 – 3 = 2 |
| 3 | * | Multiplication | 5 * 3 = 15 |
| 4 | / | Division | 5 / 2 = 2.5 |
| 5 | // | Floor Division | 5 // 2 = 2 |
| 6 | % | Modulus | 5 % 2 = 1 |
| 7 | ** | Exponent | 5 ** 2 = 25 |
2. Python Assignment Operators
Assignment operators help you update the value of a variable. They make your code shorter and cleaner. Each operator changes the value on the left using the value on the right.
| Sl. No. | Operator | Meaning / Description | Equivalent Long Form | Example | |
| 1 | = | Simple assignment | x = 5 | Assigns value to variable | |
| 2 | += | Add and assign | x = x + 5 | x += 5 | |
| 3 | -= | Subtract and assign | x = x – 3 | x -= 3 | |
| 4 | *= | Multiply and assign | x = x * 4 | x *= 4 | |
| 5 | /= | Divide and assign (float result) | x = x / 2 | x /= 2 | |
| 6 | //= | Floor-divide and assign | x = x // 2 | x //= 2 | |
| 7 | %= | Modulus and assign | x = x % 3 | x %= 3 | |
| 8 | **= | Exponent (power) and assign | x = x ** 2 | x **= 2 | |
| 9 | &= | Bitwise AND and assign | x = x & 3 | x &= 3 | |
| 10 | ^= | Bitwise XOR and assign | x = x ^ 2 | x ^= 2 | |
| 11 | <<= | Left shift and assign | x = x << 1 | x <<= 1 | |
| 12 | >>= | Right shift and assign | x = x >> 1 | x >>= 1 |
3. Python Comparison Operators
Comparison operators help you compare two values, and they return a boolean value (True or False).
| Sl. No. | Operator | Description | Example |
| 1 | + | Addition | 5 + 3 = 8 |
| 2 | – | Subtraction | 5 – 3 = 2 |
| 3 | * | Multiplication | 5 * 3 = 15 |
| 4 | / | Division | 5 / 2 = 2.5 |
| 5 | // | Floor Division | 5 // 2 = 2 |
| 6 | % | Modulus | 5 % 2 = 1 |
| 7 | ** | Exponent | 5 ** 2 = 25 |
4. Python Logical Operators
Logical operators help you combine conditions in Python. They return True or False based on the result.
| Sl. No. | Operator | Meaning | Description | Example | Result |
| 1 | and | Logical AND | True only if both conditions are True | 5 > 2 and 3 < 4 | True |
| 2 | or | Logical OR | True if at least one condition is True | 5 > 10 or 3 < 4 | True |
| 3 | not | Logical NOT | Reverses the result of a condition | not(5 > 2) | False |
5. Python Bitwise Operators
Bitwise operators work on binary representations of numbers.
| Sl. No. | Operator | Description |
| 1 | & | AND |
| 2 | ` | ` |
| 3 | ^ | XOR |
| 4 | ~ | NOT |
| 5 | << | Left Shift |
| 6 | >> | Right Shift |
6. Python Membership Operators
Membership operators check whether a value exists inside a sequence. They return True or False.
| Sl. No. | Operator | Meaning | Description | Example | Result |
| 1 | in | Value present | True if the value is found in the sequence | “a” in “apple” | True |
| 2 | not in | Value not present | True if the value is not found in the sequence | 3 not in [1, 2, 4] | True |
7. Python Identity Operators
Identity operators check whether two variables refer to the same object in memory.
They are different from comparison operators.
| Sl. Nos. | Operator | Meaning | Description | Example | Result |
| 1 | is | Same object | True if both variables point to the same object | x is y | True / False |
| 2 | is not | Not same object | True if both variables point to different objects | x is not y | True / False |