---
title: "Explain the Python Operators with example in explained way."  
description: "Explain the Python Operators with example in explained way."  
author: "ICSM Computer"  
published: 2025-09-21  
updated: 2025-09-21  
canonical: https://www.mindstick.com/forum/161919/explain-the-python-operators-with-example-in-explained-way  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 5 minutes  

---

# Explain the Python Operators with example in explained way.

**[Explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) the Python [Operators](https://www.mindstick.com/articles/716/php-operators) with example in explained way.**

## Replies

### Reply by Anubhav Sharma

> Operators are **symbols or keywords** in [Python that perform operations](https://www.mindstick.com/blog/305589/python-tutorial-for-beginners-learn-python-step-by-step) on **variables and values**.

## Example:

```python
x = 10
y = 5
print(x + y)  # + is an operator → output: 15
```

## 1. Arithmetic Operators

Used for basic math operations.

| Operator | Description | Example | Result |
| --- | --- | --- | --- |
| `+` | Addition | `10 + 5` | `15` |
| `-` | Subtraction | `10 - 5` | `5` |
| `*` | Multiplication | `10 * 5` | `50` |
| `/` | Division | `10 / 5` | `2.0` (always float) |
| `//` | Floor Division | `10 // 3` | `3` (drops decimal) |
| `%` | Modulus (remainder) | `10 % 3` | `1` |
| `**` | Exponentiation | `2 ** 3` | `8` |

Example:

```python
a, b = 10, 3
print(a + b)   # 13
print(a / b)   # 3.333...
print(a // b)  # 3
print(a % b)   # 1
print(a ** b)  # 1000
```

## 2. Comparison (Relational) Operators

Used to compare two values → return `True` or `False`.

| Operator | Description | Example | Result |
| --- | --- | --- | --- |
| `==` | Equal to | `5 == 5` | True |
| `!=` | Not equal | `5 != 3` | True |
| `>` | Greater than | `5 > 3` | True |
| `<` | Less than | `5 < 3` | False |
| `>=` | Greater than or equal | `5 >= 5` | True |
| `<=` | Less than or equal | `3 <= 5` | True |

Example:

```python
x, y = 7, 10
print(x == y)  # False
print(x < y)   # True
print(x >= 7)  # True
```

## 3. Assignment Operators

Used to assign values to variables (sometimes with an operation).

| Operator | Example | Equivalent To |
| --- | --- | --- |
| `=` | `x = 5` | assigns value |
| `+=` | `x += 3` | `x = x + 3` |
| `-=` | `x -= 2` | `x = x - 2` |
| `*=` | `x *= 4` | `x = x * 4` |
| `/=` | `x /= 2` | `x = x / 2` |
| `//=` | `x //= 3` | `x = x // 3` |
| `%=` | `x %= 2` | `x = x % 2` |
| `**=` | `x **= 3` | `x = x ** 3` |

Example:

```python
x = 10
x += 5   # x = 15
x *= 2   # x = 30
print(x)
```

## 4. Logical Operators

Used for **logical conditions** (returns `True`/`False`).

| Operator | Example | Meaning |
| --- | --- | --- |
| `and` | `(x > 5 and y < 10)` | True if **both** conditions are True |
| `or` | `(x > 5 or y < 10)` | True if **at least one** condition is True |
| `not` | `not(x > 5)` | Reverses result |

Example:

```python
x, y = 8, 3
print(x > 5 and y < 5)  # True
print(x > 10 or y < 5)  # True
print(not(x > 5))       # False
```

## 5. Identity Operators

Used to check if **two objects are the same in memory**.

| Operator | Example | Meaning |
| --- | --- | --- |
| `is` | `x is y` | True if same object |
| `is not` | `x is not y` | True if not same object |

Example:

```python
a = [1, 2, 3]
b = a
c = [1, 2, 3]

print(a is b)      # True (same object in memory)
print(a is c)      # False (same content, but different objects)
print(a == c)      # True (values are equal)
```

## 6. Membership Operators

Used to check if a **value is inside a sequence** (list, tuple, string, etc.).

| Operator | Example | Meaning |
| --- | --- | --- |
| `in` | `"a" in "apple"` | True |
| `not in` | `"z" not in "apple"` | True |

Example:

```python
fruits = ["apple", "banana", "cherry"]
print("apple" in fruits)     # True
print("mango" not in fruits) # True
```

## 7. Bitwise Operators

Work at the **bit level** (binary representation).

| Operator | Example | Meaning |
| --- | --- | --- |
| `&` | `5 & 3` | AND |
| ` | ` | `5 |
| `^` | `5 ^ 3` | XOR |
| `~` | `~5` | NOT (inverts bits) |
| `<<` | `5 << 1` | Left shift |
| `>>` | `5 >> 1` | Right shift |

Example:

```python
x, y = 5, 3  # 5 = 0101, 3 = 0011 (binary)

print(x & y)   # 1  (0101 & 0011 = 0001)
print(x | y)   # 7  (0101 | 0011 = 0111)
print(x ^ y)   # 6  (0101 ^ 0011 = 0110)
print(x << 1)  # 10 (0101 << 1 = 1010)
print(x >> 1)  # 2  (0101 >> 1 = 0010)
```

## Summary

- **Arithmetic** → Math (`+ - * / % // **`)
- **Comparison** → Compare values (`== != > < >= <=`)
- **Assignment** → Assign/update (`= += -= ...`)
- **Logical** → Boolean logic (`and, or, not`)
- **Identity** → Same object? (`is, is not`)
- **Membership** → Inside sequence? (`in, not in`)
- **Bitwise** → Binary operations (`& | ^ ~ << >>`)


---

Original Source: https://www.mindstick.com/forum/161919/explain-the-python-operators-with-example-in-explained-way

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
