Python Operators Explained for Beginners (+, -,/, %, //, **)
Python Operators Explained for Beginners (+, -, *, /, %, //, **)
Introduction
In the previous post, we learned about Python input and output. Now it’s time to perform calculations and operations using Python operators.
Operators are symbols that tell Python to perform a specific operation.
---What is an Operator?
An operator is a symbol used to perform operations on variables and values.
1️⃣ Addition Operator (+)
The + operator is used to add two values.
a = 10
b = 5
print(a + b)
Output: 15
---2️⃣ Subtraction Operator (-)
The - operator subtracts one value from another.
a = 10
b = 3
print(a - b)
Output: 7
---3️⃣ Multiplication Operator (*)
The * operator multiplies values.
a = 4
b = 5
print(a * b)
Output: 20
---4️⃣ Division Operator (/)
The / operator divides one value by another and always returns a float.
a = 10
b = 2
print(a / b)
Output: 5.0
---5️⃣ Modulus Operator (%)
The % operator returns the remainder of a division.
a = 10
b = 3
print(a % b)
Output: 1
6️⃣ Floor Division Operator (//)
The // operator divides and returns only the integer part of the result.
a = 10
b = 3
print(a // b)
Output: 3
---7️⃣ Exponent Operator (**)
The ** operator is used to calculate power.
a = 2
b = 3
print(a ** b)
Output: 8
---Summary of Operators
- + → Addition
- - → Subtraction
- * → Multiplication
- / → Division
- % → Remainder
- // → Floor division
- ** → Power
What You Learned in This Post
- What operators are in Python
- Arithmetic operators with examples
- How Python performs calculations
What’s Next?
Now that you know operators, the next step is learning how to make decisions using conditions.
Next Post: Python Conditional Statements Explained (if, elif, else)
---👋 About the Author
Ayush Gupta
MSc AI/ML Student | Machine Learning & Python Enthusiast
📧 Email:
aygupta9898@gmail.com
Comments
Post a Comment