Python Operators and Expressions: Understanding the Basics
.Python Operators and Expressions are essential building blocks for writing efficient Python programs. In this beginner-friendly guide, you’ll learn how these operators work, how expressions are evaluated, and how to use them to perform calculations, comparisons, and logical decisions in your Python code. Welcome to our Python for Beginners series! In this lesson, we’ll dive into Python operators and expressions, essential concepts that allow you to perform calculations, compare values, and control the flow of your programs. Understanding these basics is crucial for writing effective and efficient Python code.
By the end of this guide, you’ll be comfortable using Python operators and expressions in real-world scenarios, including arithmetic, comparison, logical operations, and more. Let’s get started
Welcome back to our Python for Beginners series!
In the previous lessons, we covered:
What Python is and why it’s popular
How to create and use variables
Basic data types like int, float, string, and bool
How to take input from the user and display output
Now it’s time to level up — let’s learn how to perform operations with those variables using operators.
What Are Operators?
Operators are symbols that tell Python to perform a certain operation, like addition, comparison, or logical decision-making.
For example:
a =
b =
print(a + b) # Adds two numbers
Here, + is an operator that adds the two operands a and b.
a and b are called operands — the values on which the operation is performed.
1. Arithmetic Operators
Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication, etc.
| Operator | Description | Example | Output |
| + | Addition | 5 + 3 | 8 |
| – | Subtraction | 9 – 4 | 5 |
| * | Multiplication | 6 * 2 | 12 |
| / | Division (returns float) | 10 / 4 | 2.5 |
| // | Floor Division (integer part only) | 10 // 4 | 2 |
| % | Modulus (remainder) | 10 % 4 | 2 |
| ** | Exponentiation (power) | 2 ** 3 | 8 |
Example:
a =
b =
print(“Addition:”, a + b)
print(“Subtraction:”, a – b)
print(“Multiplication:”, a * b)
print(“Division:”, a / b)
print(“Floor Division:”, a // b)
print(“Remainder:”, a % b)
print(“Power:”, a ** b)
Output:
Addition:13
Subtraction:7
Multiplication:30
Division:3.3333333333333335
Floor Division:3
Remainder:1
Power:1000
2. Comparison Operators
Comparison operators help us compare two values.
They return a Boolean value — either True or False.
| Operator | Description | Example | Result |
| == | Equal to | 5 == 5 | True |
| != | Not equal to | 5 != 3 | True |
| > | Greater than | 8 > 5 | True |
| < | Less than | 2 < 10 | True |
| >= | Greater than or equal to | 5 >= 5 | True |
| <= | Less than or equal to | 3 <= 2 | False |
Example:
a =
b =
print(a == b) # False
print(a != b) # True
print(a > b) # True
print(a < b) # False
print(a >= b) # True
print(a <= b) # False
3. Logical Operators
Logical operators are used to combine conditional statements (i.e., comparisons).
They are extremely important in decision-making and control flow (which we’ll explore in the next post!).
| Operator | Meaning | Example | Output |
| and | True only if both conditions are True | (5 > 3) and (8 > 6) | True |
| or | True if at least one condition is True | (5 > 10) or (8 > 6) | True |
| not | Reverses the condition | not(5 > 3) | False |
Example:
x =
print(x > 5and x < 20) # True (both conditions are true)
print(x > 15or x == 10) # True (second condition is true)
print(not(x == 10)) # False (because x == 10 is True)
4. Assignment Operators
Assignment operators are used to assign values to variables and even update them easily.
| Operator | Example | Same As |
| = | x = 5 | Assigns value 5 to x |
| += | x += 3 | x = x + 3 |
| -= | x -= 2 | x = x – 2 |
| *= | x *= 2 | x = x * 2 |
| /= | x /= 2 | x = x / 2 |
| //= | x //= 3 | x = x // 3 |
| %= | x %= 2 | x = x % 2 |
| **= | x **= 3 | x = x ** 3 |
Example:
x =
x +=
print(x) # 15
x *=
print(x) # 30
x //=
print(x) # 7
5. Bitwise Operators (Optional but Fun!)
Bitwise operators work on binary numbers (bits: 0 and 1).
They are mostly used in low-level programming, but it’s good to know them.
| Operator | Meaning | Example | Result |
| & | AND | 5 & 3 | 1 |
| ` | ` | OR | `5 |
| ^ | XOR | 5 ^ 3 | 6 |
| ~ | NOT | ~5 | -6 |
| << | Left shift | 5 << 1 | 10 |
| >> | Right shift | 5 >> 1 | 2 |
Example:
a = 5 # 0101
b = 3 # 0011
print(a & b) # 1
print(a | b) # 7
print(a ^ b) # 6
6. Expressions in Python
An expression is a combination of values, variables, and operators that produces a result.
Examples:
x =
y =
z = (x + y) * 2 # Expression
print(z) # Output: 30
Even a simple line like:
print(3 + 4)
is an expression because Python evaluates it and returns a value.
Practice Time!
Try these mini challenges
Write a program to take two numbers as input and:
Print their sum, difference, product, and remainder
Write a program to check if a number is even or odd using modulus %.
Write a program that asks for two numbers and checks:
If both are positive
If at least one is greater than 100
Bonus: Use an expression to calculate the area of a circle (πr²) given radius r.
Summary
In this post, you learned about:
Arithmetic, Comparison, Logical, and Assignment operators
How Python evaluates expressions
How to combine operators for complex conditions
These concepts are foundational — you’ll use them in almost every Python program!

