Python Operators: The Complete Master Guide with Operator Overloading
Master Python operators from basics to advanced. Learn about arithmetic, comparison, logical short-circuiting, bitwise masks, identity vs equality, operator overloading via dunder methods, and PEP 8 guidelines.
Table of Contents
- Introduction
- Learning Objectives
- Prerequisites
- Arithmetic Operators & Underlying Math
- Comparison Operators & Chained Comparisons
- Logical Operators & Short-Circuit Mechanics
- Bitwise Operators & Signed Binary Arithmetic
- Assignment & In-Place Operators
- Membership & Identity Operators
- Operator Precedence and Associativity
- Operator Overloading (Dunder Methods)
- Visual Representation of Execution Flows
- Real-World and Production Examples
- Best Practices & Common Mistakes
- Performance & Security Notes
- Interview Insights
- Frequently Asked Questions (FAQs)
- Summary
- Related Tutorials
Introduction
In programming, operators are special symbols or keywords that represent computations. They take inputs (called operands), perform operations defined by the language runtime, and return a result.
While basic math operations like + or - seem trivial, Python's operator model is remarkably sophisticated. Behind every operator lies a hook into Python's object-oriented core—known as magic methods or dunder (double underscore) methods. Furthermore, logical operators exhibit short-circuit evaluation, identity operators interact directly with CPython's memory management, and comparison operators can be chained into mathematical expressions.
This comprehensive guide will walk you through the math, memory implications, performance characteristics, and customization of every operator category in Python.
Learning Objectives
By the end of this tutorial, you will be able to:
- Explain the behavior and edge cases of all core Python operators.
- Solve modular arithmetic involving negative numbers and explain Python's floor division logic.
- Optimize search operations using membership operators with an understanding of time complexity.
- Construct complex logical expressions using short-circuiting logic to prevent runtime exceptions.
- Apply bitwise operations for system-level programming, data compression, and permissions masking.
- Implement Operator Overloading in custom classes using magic methods (e.g.,
__add__,__str__). - Differentiate between object identity (
is) and value equality (==) at a bytecode level.
Prerequisites
Before diving into this guide, ensure you are familiar with:
- Python Variables & Data Types — specifically the concepts of object references, mutability, and basic data types like integers, floats, lists, and dicts.
Arithmetic Operators & Underlying Math
Arithmetic operators perform standard mathematical operations on numeric types (int, float, complex).
| Operator | Name | Example | Description | Magic Method |
| :--- | :--- | :--- | :--- | :--- |
| + | Addition | a + b | Adds two operands | __add__(self, other) |
| - | Subtraction | a - b | Subtracts right operand from left | __sub__(self, other) |
| * | Multiplication | a * b | Multiplies two operands | __mul__(self, other) |
| / | True Division | a / b | Divides left by right, always returns a float | __truediv__(self, other)|
| // | Floor Division | a // b | Divides left by right, rounds down to nearest integer | __floordiv__(self, other)|
| % | Modulus | a % b | Returns the remainder of division | __mod__(self, other) |
| ** | Exponentiation | a ** b | Left operand raised to the power of right | __pow__(self, other) |
Division Mechanics: True vs. Floor Division
Python makes a clear distinction between True Division (/) and Floor Division (//).
- True Division (
/) always yields a float, even if the operands are integers and divide evenly:print(6 / 3) # Output: 2.0 (float) print(5 / 2) # Output: 2.5 (float) - Floor Division (
//) divides the numbers and rounds the result down to the nearest whole integer (towards negative infinity). If either operand is a float, the result is a float representing a whole number:print(5 // 2) # Output: 2 (int) print(-5 // 2) # Output: -3 (int, rounded down from -2.5) print(5.0 // 2) # Output: 2.0 (float)
Modulus with Negative Numbers
The modulus operator (%) returns the remainder of a division. In Python, modulus is mathematically defined in relation to floor division:
$$r = x \pmod y = x - y \times (x \mathbin{/\mkern-6mu/} y)$$
This relationship leads to interesting results when dealing with negative numbers, which often appear in competitive programming and technical interviews:
# Case 1: Positive operands
# 10 % 3 = 10 - 3 * (10 // 3) = 10 - 3 * 3 = 1
print(10 % 3) # Output: 1
# Case 2: Negative numerator
# -10 % 3 = -10 - 3 * (-10 // 3) = -10 - 3 * (-4) = -10 + 12 = 2
print(-10 % 3) # Output: 2
# Case 3: Negative denominator
# 10 % -3 = 10 - (-3) * (10 // -3) = 10 - (-3) * (-4) = 10 - 12 = -2
print(10 % -3) # Output: -2
> [!IMPORTANT] > In Python, the result of the modulus operation always takes the sign of the denominator (divisor), unlike C++ or Java where it takes the sign of the numerator (dividend).
Comparison Operators & Chained Comparisons
Comparison operators compare the values of two operands and return a boolean (True or False).
| Operator | Description | Magic Method |
| :--- | :--- | :--- |
| == | Equal to | __eq__(self, other) |
| != | Not equal to | __ne__(self, other) |
| > | Greater than | __gt__(self, other) |
| < | Less than | __lt__(self, other) |
| >= | Greater than or equal to | __ge__(self, other) |
| <= | Less than or equal to | __le__(self, other) |
Chained Comparisons
Python supports chaining comparison operators, a feature that aligns closely with mathematical notation. For example, to check if a variable x is between 1 and 10 inclusive, you can write:
x = 5
print(1 <= x <= 10) # Output: True
Internally, Python translates a < b < c to:
a < b and b < c
However, there is a critical optimization: the middle expression is evaluated only once. This is highly beneficial if the middle expression is a function call with side effects or computationally expensive operations:
def get_threshold():
print("Function called!")
return 10
# The function get_threshold() is called exactly once.
print(5 < get_threshold() < 20)
# Output:
# Function called!
# True
Logical Operators & Short-Circuit Mechanics
Logical operators are used to combine conditional statements.
| Operator | Description | Example |
| :--- | :--- | :--- |
| and | Returns True if both statements are true | x < 5 and x < 10 |
| or | Returns True if at least one statement is true | x < 5 or x < 4 |
| not | Reverse the result, returns False if the result is true | not(x < 5) |
Short-Circuit Evaluation
Python logical operators use short-circuit evaluation. This means the second operand is evaluated only if the first operand is not sufficient to determine the result of the expression.
andShort-Circuit Rule: If the left operand is false, the entire expression must be false. Python stops evaluation immediately and returns the left operand.orShort-Circuit Rule: If the left operand is true, the entire expression must be true. Python stops evaluation immediately and returns the left operand.
def is_ok():
print("is_ok evaluated")
return True
def is_bad():
print("is_bad evaluated")
return False
# Evaluation stops at is_bad() because False and ... is always False.
# is_ok() will NOT be executed.
print(is_bad() and is_ok())
# Output:
# is_bad evaluated
# False
Return Values of Logical Expressions
In Python, logical operators do not strictly return True or False. Instead, they return the value of the last evaluated operand.
# The string "Hello" is truthy. The integer 0 is falsy.
# Since the left side of "or" is truthy, the evaluation short-circuits and returns "Hello".
result1 = "Hello" or "World"
print(result1) # Output: "Hello"
# "and" requires checking both if the left is truthy.
# "Hello" is truthy, so evaluation continues and returns the right operand: []
result2 = "Hello" and []
print(result2) # Output: []
This behavior is frequently used in production code to assign default fallback values:
# If custom_timeout is None or 0 (falsy), fallback to default value of 30
timeout = custom_timeout or 30
Bitwise Operators & Signed Binary Arithmetic
Bitwise operators perform calculations directly on the binary representations of integers.
| Operator | Name | Description | Example |
| :--- | :--- | :--- | :--- |
| & | Bitwise AND | Sets each bit to 1 if both bits are 1 | x & y |
| \| | Bitwise OR | Sets each bit to 1 if one of two bits is 1 | x \| y |
| ^ | Bitwise XOR | Sets each bit to 1 if only one of two bits is 1 | x ^ y |
| ~ | Bitwise NOT | Inverts all the bits (flips 0 to 1 and 1 to 0) | ~x |
| << | Zero fill left shift | Shift left by pushing zeros in from the right | x << 2 |
| >> | Signed right shift | Shift right by pushing copies of the leftmost bit | x >> 2 |
Two's Complement Representation
Python integers are of arbitrary precision, but internally they represent negative numbers using Two's Complement.
For any integer x, the bitwise NOT operation ~x is equivalent to:
$$\sim x = -(x + 1)$$
Let's look at why:
x = 5 # Binary: 0000 0101
print(~x) # Output: -6 (Binary representation in two's complement: ...1111 1010)
Bit Shifting Math
- Left Shift (
<<) shifts bits to the left, filling empty spaces with0. Shifting left bynbits is mathematically equivalent to multiplying by $2^n$:x = 10 # Binary: 1010 print(x << 2) # Output: 40 (Binary: 101000, equivalent to 10 * 2^2) - Right Shift (
>>) shifts bits to the right. Shifting right bynbits is equivalent to floor-dividing by $2^n$:x = 40 # Binary: 101000 print(x >> 2) # Output: 10 (Binary: 1010)
Assignment & In-Place Operators
Assignment operators are used to write or update values in variables.
| Operator | Equivalent | Description |
| :--- | :--- | :--- |
| = | x = 5 | Assigns value to variable |
| += | x = x + 5 | Add and Assign |
| -= | x = x - 5 | Subtract and Assign |
| *= | x = x * 5 | Multiply and Assign |
| /= | x = x / 5 | Divide and Assign |
| //= | x = x // 5 | Floor Divide and Assign |
| %= | x = x % 5 | Modulus and Assign |
| **= | x = x ** 5 | Exponentiate and Assign |
| &= | x = x & 5 | Bitwise AND and Assign |
| \|= | x = x \| 5 | Bitwise OR and Assign |
| ^= | x = x ^ 5 | Bitwise XOR and Assign |
| <<= | x = x << 2 | Bitwise Left Shift and Assign |
| >>= | x = x >> 2 | Bitwise Right Shift and Assign |
| := | (x := 5) | Walrus Operator (Assigns and returns value) |
In-Place Operators on Mutable vs. Immutable Objects
In-place operators (like += or *=) behave differently depending on whether the object is mutable or immutable:
- Immutable Objects (
int,str,tuple): The variable is reassigned to a new object in memory. The original object is unchanged.# Int is immutable a = 10 print(id(a)) # E.g. Address: 140706822 a += 5 print(id(a)) # Address changes: 140706902 (New object created!) - Mutable Objects (
list,set,dict): The object is modified in-place. Its memory address (id()) remains identical.# List is mutable lst1 = [1, 2] print(id(lst1)) # E.g. Address: 2011048896 lst1 += [3] print(id(lst1)) # Address remains: 2011048896 (Modified in-place!)
The Walrus Operator (:=)
Introduced in Python 3.8, the Assignment Expression operator (colloquially called the Walrus Operator) allows you to assign values to variables as part of a larger expression.
# Traditional approach
data = fetch_api_response()
if len(data) > 0:
print(f"Data received: {data}")
# Walrus approach (calculates, assigns, and evaluates in one line)
if (n := len(fetch_api_response())) > 0:
print(f"Data received with size {n}")
Membership & Identity Operators
These operators check relationships between variables, containers, and objects in memory.
Membership Operators (in, not in)
Membership operators test whether a value or variable is found in a sequence (such as a string, list, tuple, set, or dictionary).
languages = ["Python", "Rust", "Go"]
print("Python" in languages) # Output: True
print("Java" not in languages) # Output: True
> [!TIP]
> Performance Note: Checking membership with in in a list or tuple takes $O(n)$ linear time. In contrast, checking membership in a set or dict takes $O(1)$ constant time because these collections use hash tables.
Identity Operators (is, is not)
Identity operators compare the memory addresses of two objects to check if they are the exact same instance in memory.
isevaluates toTrueif both variables point to the same object in memory.is notevaluates toTrueif variables point to different objects.
a = [1, 2, 3]
b = [1, 2, 3]
c = a
# Equality check (compares values)
print(a == b) # Output: True (values are identical)
# Identity check (compares memory addresses)
print(a is b) # Output: False (different objects in memory)
print(a is c) # Output: True (c points to the exact same list object as a)
Object Interning Optimization
To save memory, Python pre-caches (interns) small integer objects between -5 and 256, as well as short string literals. This leads to behavior that can surprise developers:
x = 100
y = 100
print(x is y) # Output: True (Both variables reference the cached integer object)
x = 300
y = 300
print(x is y) # Output: False (300 falls outside the interned range; new objects are created)
Operator Precedence and Associativity
When multiple operators appear in a single expression, Python evaluates them based on precedence (which operator runs first) and associativity (direction of evaluation when operators have the same precedence).
Precedence Table (Highest to Lowest)
| Order | Operator | Description | Associativity |
| :--- | :--- | :--- | :--- |
| 1 | ( ) | Parentheses (grouping) | Left-to-right |
| 2 | ** | Exponentiation | Right-to-left |
| 3 | +x, -x, ~x | Unary plus, Unary minus, Bitwise NOT | Right-to-left |
| 4 | *, /, //, % | Multiplication, Division, Floor division, Modulus | Left-to-right |
| 5 | +, - | Addition, Subtraction | Left-to-right |
| 6 | <<, >> | Bitwise left and right shifts | Left-to-right |
| 7 | & | Bitwise AND | Left-to-right |
| 8 | ^ | Bitwise XOR | Left-to-right |
| 9 | \| | Bitwise OR | Left-to-right |
| 10 | ==, !=, >, >=, <, <=, is, is not, in, not in | Comparisons, Identity, Membership | Left-to-right |
| 11 | not | Logical NOT | Right-to-left |
| 12 | and | Logical AND | Left-to-right |
| 13 | or | Logical OR | Left-to-right |
| 14 | := | Walrus operator | Right-to-left |
Exponentiation Associativity Gotcha
Most operators in Python associate from left to right. However, the exponentiation operator (**) associates from right to left:
# 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2) -> 2 ** 9 -> 512
# It is NOT evaluated as (2 ** 3) ** 2 -> 8 ** 2 -> 64
print(2 ** 3 ** 2) # Output: 512
Operator Overloading (Dunder Methods)
Python allows custom classes to define how they respond to built-in operators. This is called Operator Overloading. It is accomplished by writing special dunder methods inside your class.
For example, when you write obj1 + obj2, Python internally executes:
obj1.__add__(obj2)
Implementing Operator Overloading
Here is a complete, production-ready class representing a 2D Vector that implements arithmetic addition, multiplication, comparison equality, and string representation:
class Vector2D:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
# String representation (readable format)
def __str__(self) -> str:
return f"Vector2D({self.x}, {self.y})"
# Overloading the Addition (+) operator
def __add__(self, other: "Vector2D") -> "Vector2D":
if not isinstance(other, Vector2D):
raise TypeError("Operand must be of type Vector2D")
return Vector2D(self.x + other.x, self.y + other.y)
# Overloading the Multiplication (*) operator (scalar multiplication)
def __mul__(self, scalar: float) -> "Vector2D":
if not isinstance(scalar, (int, float)):
raise TypeError("Can only multiply vector by a numeric scalar")
return Vector2D(self.x * scalar, self.y * scalar)
# Overloading the Equality (==) operator
def __eq__(self, other: object) -> bool:
if not isinstance(other, Vector2D):
return False
return self.x == other.x and self.y == other.y
# Test operations
v1 = Vector2D(2, 4)
v2 = Vector2D(1, 3)
# Test Addition
v3 = v1 + v2
print(v3) # Output: Vector2D(3, 7)
# Test Multiplication
v4 = v1 * 3
print(v4) # Output: Vector2D(6, 12)
# Test Equality
v5 = Vector2D(2, 4)
print(v1 == v5) # Output: True
print(v1 == v2) # Output: False
Visual Representation of Execution Flows
Below is a visual layout illustrating the short-circuit evaluation pipeline for logical expressions in Python.
Logical AND/OR Short-Circuit Evaluation Flow
graph TD
A[Start Evaluation of Expression] --> B{Is operator AND or OR?}
B -- AND --> C[Evaluate Left Operand]
C --> D{Is Left Operand Truthy?}
D -- Yes --> E[Evaluate Right Operand]
E --> F[Return Right Operand Value]
D -- No --> G[Stop: Short-Circuit]
G --> H[Return Left Operand Value]
B -- OR --> I[Evaluate Left Operand]
I --> J{Is Left Operand Truthy?}
J -- Yes --> K[Stop: Short-Circuit]
K --> L[Return Left Operand Value]
J -- No --> M[Evaluate Right Operand]
M --> N[Return Right Operand Value]
Real-World and Production Examples
Example 1: Bitwise Flags for Permissions Masking
In high-performance API designs, permission systems often use binary bitmasks instead of database strings to check access levels.
# Define permission bitmasks (powers of 2)
PERMISSION_READ = 1 << 0 # 0001 (Decimal: 1)
PERMISSION_WRITE = 1 << 1 # 0010 (Decimal: 2)
PERMISSION_EXECUTE = 1 << 2 # 0100 (Decimal: 4)
PERMISSION_ADMIN = 1 << 3 # 1000 (Decimal: 8)
class UserSession:
def __init__(self, username: str, permissions: int = 0):
self.username = username
self.permissions = permissions # Holds the bitmask integer
def grant_permission(self, permission: int):
# Bitwise OR to enable specific bits
self.permissions |= permission
def revoke_permission(self, permission: int):
# Bitwise AND with inverted bits to disable specific bits
self.permissions &= ~permission
def has_permission(self, permission: int) -> bool:
# Bitwise AND comparison
return (self.permissions & permission) == permission
# Test permissions system
session = UserSession("developer_bob")
# Grant Read & Write permissions
session.grant_permission(PERMISSION_READ | PERMISSION_WRITE)
print(f"Can Read: {session.has_permission(PERMISSION_READ)}") # Output: True
print(f"Can Execute: {session.has_permission(PERMISSION_EXECUTE)}") # Output: False
# Grant Admin access and check
session.grant_permission(PERMISSION_ADMIN)
print(f"Is Admin: {session.has_permission(PERMISSION_ADMIN)}") # Output: True
Example 2: Ingestion Loop with the Walrus Operator
Reading lines of text from files or networks can be written concisely with the walrus operator.
import io
# Simulate a network stream
stream = io.StringIO("Log Entry 1\nLog Entry 2\n[EOF]\nShould not print this")
# Read lines until '[EOF]' marker is hit
while (line := stream.readline().strip()) != "[EOF]" and line:
print(f"Processing: {line}")
# Output:
# Processing: Log Entry 1
# Processing: Log Entry 2
Best Practices & Common Mistakes
Best Practices
- Use Parentheses to Enforce Readability: Even if you memorize the precedence table, code readers may not. Express intent explicitly:
# Hard to read val = x & y == z or a not in b # Clear and readable val = ((x & y) == z) or (a not in b) - Prefer
is NoneOver== None: Checking if an object is null (None) should always be done with the identity operatoris. This is because==can be overridden by a class's custom__eq__method, whereasiscannot.
Common Mistakes
- Mutating Tuples Containing Lists: While tuples are immutable, the objects they hold can be mutable. Modifying a list inside a tuple works, but performing in-place operators (
+=) on them will raise aTypeErrorwhile still successfully modifying the list:tup = (1, 2, [3, 4]) try: tup[2] += [5] # Raises TypeError except TypeError: pass print(tup) # Output: (1, 2, [3, 4, 5]) (List WAS modified!) - Logical Pitfall with Boolean Inversion (
not): Remember thatnothas a low precedence. Writeif not (x > 5 and y < 10):instead ofif not x > 5 and y < 10:, which groups as(not x > 5) and y < 10.
Performance & Security Notes
Membership Checks: Lists vs. Sets
Always convert collections to a set if you plan to query membership repeatedly in a loop. Let's compare execution time using python's built-in libraries:
import time
# Create a list and a set with 1,000,000 integers
data_list = list(range(1_000_000))
data_set = set(data_list)
# Search for elements not in collections
# List lookup is O(N)
start = time.perf_counter()
999_999 in data_list
end = time.perf_counter()
print(f"List search took: {end - start:.6f} seconds")
# Set lookup is O(1)
start = time.perf_counter()
999_999 in data_set
end = time.perf_counter()
print(f"Set search took: {end - start:.6f} seconds")
Typical results show set searches executing over 10,000 times faster for large datasets.
Short-Circuit for Safety
Always place validation constraints on the left of and operators to prevent runtime errors:
# Safe: If user is None, short-circuit stops evaluation before checking attribute
if user is not None and user.role == "admin":
pass
# Unsafe: Raises AttributeError: 'NoneType' object has no attribute 'role'
if user.role == "admin" and user is not None:
pass
Interview Insights
Typical Interview Questions:
-
What is the difference between
==andisin Python? Answer Key:==checks for value equality (compares if the contents are equivalent).ischecks for object identity (compares if both variables point to the exact same address in memory). -
Explain how Python evaluates the expression
1 < x < 5. Answer Key: Python chains comparisons. The expression is evaluated as1 < x and x < 5. The crucial detail is thatxis only evaluated once. -
Why does
10 // -3equal-4instead of-3? Answer Key: Python's floor division (//) rounds down towards negative infinity (the floor). Since $10 / -3 = -3.333...$, rounding down yields-4. -
What is the Walrus Operator and when should it be used? Answer Key: The walrus operator
:=is the assignment expression operator. It assigns a value to a variable and returns that value inside a single expression. It is best used in while loops (reading streams) and list comprehensions to avoid duplicate calculations.
Frequently Asked Questions (FAQs)
Q: Can we override comparison operators to return something other than booleans?
A: Yes, custom classes can return any data type from magic comparison methods like __lt__ or __eq__. For instance, scientific libraries like NumPy override these operators to return arrays of boolean elements.
Q: Why doesn't Python support increment (++) and decrement (--) operators?
A: In Python, integers are immutable. The operator ++x is parsed as two unary plus operators on x (+(+x)), which evaluates to x. Python prefers explicit assignments like x += 1 to align with the core philosophy "Explicit is better than implicit".
Summary
Python operators are highly readable yet powerful utilities. They connect directly to object methods (dunder methods), allowing developers to build custom domains with Operator Overloading. By mastering precedence, bitwise configurations, identity optimizations, and short-circuit parameters, you can write clean, professional-grade code that is optimized for both execution speed and clarity.
Related Tutorials
- Control Flow: Conditional Branching with If-Else
- Python Loops: Iteration & Range Controls
- Working with Python Strings
Technical SEO Schema Metadata
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Article",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://vsnexos.com/placement-prep/python/operators"
},
"headline": "Python Operators: The Complete Master Guide with Operator Overloading",
"description": "Master Python operators from basics to advanced. Learn arithmetic, logic, short-circuits, bitwise masking, identity verification, and custom magic methods.",
"image": "https://vsnexos.com/images/courses/python-operators.png",
"author": {
"@type": "Organization",
"name": "Vsnexos"
},
"publisher": {
"@type": "Organization",
"name": "Vsnexos",
"logo": {
"@type": "ImageObject",
"url": "https://vsnexos.com/images/logo.png"
}
}
},
{
"@type": "Course",
"name": "Python Zero to Hero Master Course",
"description": "A comprehensive course to transform beginners into industry-ready Python developers.",
"provider": {
"@type": "Organization",
"name": "Vsnexos",
"sameAs": "https://vsnexos.com"
}
},
{
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://vsnexos.com"
},
{
"@type": "ListItem",
"position": 2,
"name": "Placement Prep",
"item": "https://vsnexos.com/placement-prep"
},
{
"@type": "ListItem",
"position": 3,
"name": "Python Course",
"item": "https://vsnexos.com/placement-prep/python"
},
{
"@type": "ListItem",
"position": 4,
"name": "Python Operators",
"item": "https://vsnexos.com/placement-prep/python/operators"
}
]
},
{
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the difference between == and is in Python?",
"acceptedAnswer": {
"@type": "Answer",
"text": "== compares the values of two objects, while is checks if both variables refer to the exact same object in memory."
}
},
{
"@type": "Question",
"name": "Why does 10 // -3 return -4 in Python?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Floor division // rounds the result down to the nearest integer towards negative infinity. 10 / -3 evaluates to -3.333, and rounding down yields -4."
}
},
{
"@type": "Question",
"name": "Does Python support ++ or -- increment operators?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No, Python does not support ++ or -- operators. Since integers are immutable, values must be incremented explicitly using x += 1."
}
}
]
}
]
}