What students Say?
Here are the stdudents...
Arithmetic operators are used with numeric values to perform common mathematical operations. In Python, these operators support integers, floating-point numbers, and even complex numbers.
| Operator | Name | Description | Example | Output |
|---|---|---|---|---|
| + | Addition | Adds two operands together. | 15 + 5 | 20 |
| - | Subtraction | Subtracts the right operand from the left. | 50 - 20 | 30 |
| * | Multiplication | Multiplies two operands. | 4 * 3.5 | 14.0 |
| / | Division | Divides the left operand by the right. Always returns a float. | 10 / 4 | 2.5 |
| % | Modulus | Returns the remainder after division. | 10 % 3 | 1 |
| ** | Exponentiation | Left operand raised to the power of the right. | 2 ** 4 | 16 |
| // | Floor Division | Divides and rounds down to the nearest whole number. | 10 // 3 | 3 |
Python handles division differently than many languages. Standard division (/) always results in a decimal, while Floor Division (//) "chops off" the decimal part.
# Mixed Type Arithmetic
print(5 + 2.0) # Result: 7.0 (Int + Float = Float)
# Negative Floor Division
print(-10 // 3) # Result: -4 (Rounds down to the smaller integer)
# String Repetition
print("Hi! " * 3) # Result: Hi! Hi! Hi!
Assignment operators are used to store values in variables. Compound assignment operators (like +=) are used to update the value of a variable based on its current value.
| Operator | Example | Same As | Description |
|---|---|---|---|
| = | x = 10 | x = 10 | Simple assignment |
| += | x += 5 | x = x + 5 | Add and Assign |
| -= | x -= 2 | x = x - 2 | Subtract and Assign |
| *= | x *= 3 | x = x * 3 | Multiply and Assign |
| /= | x /= 2 | x = x / 2 | Divide and Assign |
| %= | x %= 3 | x = x % 3 | Modulus and Assign |
| **= | x **= 2 | x = x ** 2 | Power and Assign |
Compound operators make the code more concise and are generally more efficient for the Python interpreter to execute.
count = 0
count += 1 # Increments by 1
count += 1 # count is now 2
# Usage in a loop
total = 100
total *= 1.10 # Adds 10% tax/interest
Comparison operators evaluate the relationship between two operands. The result is always a Boolean (True or False). These are the backbone of conditional logic.
| Operator | Name | Example | Result |
|---|---|---|---|
| == | Equal to | 10 == 10 | True |
| != | Not Equal to | 10 != 5 | True |
| > | Greater than | 20 > 15 | True |
| < | Less than | 5 < 10 | True |
| >= | Greater or equal | 15 >= 15 | True |
| <= | Less or equal | 8 <= 10 | True |
5 == 5.0 is True)."Python" == "python" is False.Logical operators are used to combine multiple conditional statements. They are often used in if statements to check if several criteria are met.
| Operator | Logic | Condition to return True |
|---|---|---|
| and | x and y | If BOTH x and y are True |
| or | x or y | If AT LEAST ONE of x or y is True |
| not | not x | Returns True if x is False (Inverts result) |
Python is smart: in an or statement, if the first part is True, it won't even look at the second part. In an and statement, if the first part is False, it stops immediately.
age = 25
has_license = True
if age >= 18 and has_license:
print("You can drive!")
is_weekend = False
is_holiday = True
if is_weekend or is_holiday:
print("Office is closed.")
These check if a value is part of a collection (like a list, tuple, set, or string).
fruits = ["apple", "mango", "orange"]
print("mango" in fruits) # True
print("banana" not in fruits) # True
Identity operators compare the memory location of two objects. They check if two variables are the exact same instance.
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a == b) # True (Values are same)
print(a is b) # False (Different objects in memory)
print(a is c) # True (Same object)
These operate on binary digits (bits) of integers. They are used in low-level programming, graphics, and network protocols.
| Symbol | Name | Action |
|---|---|---|
| & | AND | Sets bit to 1 if both bits are 1 |
| | | OR | Sets bit to 1 if one of the bits is 1 |
| ^ | XOR | Sets bit to 1 if only one of the bits is 1 |
| ~ | NOT | Inverts all bits (-(x+1)) |
| << | Left Shift | Moves bits left, filling with zeros (Multiplies by 2) |
| >> | Right Shift | Moves bits right (Divides by 2) |
A unary operator is an operator that takes only one operand. The most common is the unary minus to indicate negative numbers.
x = 10
print(-x) # Result: -10
print(+x) # Result: 10
# Bitwise Unary
print(~x) # Result: -11
Operator precedence decides the order of evaluation of operators in an expression. It ensures that expressions are evaluated properly and consistently.
Brackets → Maths → Comparison → Logic → Assignment (B → M → C → L → A)
| Priority | Operators | Description |
|---|---|---|
| 1 | () | Parentheses (Highest) |
| 2 | ** | Exponentiation |
| 3 | Unary + - | Positive, Negative |
| 4 | * / // % | Multiplication, Division, Floor Div, Modulo |
| 5 | + - | Addition, Subtraction |
| 6 | << >> | Bitwise Shifts |
| 7 | & | Bitwise AND |
| 8 | ^ | Bitwise XOR |
| 9 | | | Bitwise OR |
| 10 | < <= > >= == != | Comparisons |
| 11 | not | Logical NOT |
| 12 | and | Logical AND |
| 13 | or | Logical OR |
| 14 | = | Assignment (Lowest) |
# Examples
result1 = 10 + 2 * 3 # 16 (Multiplication first)
result2 = (10 + 2) * 3 # 36 (Brackets first)
result3 = 10 > 5 and 5 > 2 # True
result4 = True or False and False # True (and evaluated before or)
Here are the stdudents...
Empower your tech dreams with us. Get in touch!




