
Operators in Python – Part 1
Operators are symbols used to perform different operations on values and variables. In this first part, we'll look at arithmetic, comparison, and assignment operators.
Arithmetic Operators
Arithmetic operators are used for basic mathematical calculations.
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)Output:
13
7
30
3.3333333333333335Common arithmetic operators are:
| Operator | Meaning |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Remainder |
** | Power |
// | Floor division |
Comparison Operators
Comparison operators are used to compare two values. The result is either True or False.
a = 10
b = 5
print(a > b)
print(a == b)
print(a != b)Output:
True
False
TrueSome common comparison operators are:
==, !=, >, <, >=, <=
Assignment Operators
Assignment operators are used to store or update values in variables.
x = 10
x += 5
print(x)Output:
15Common assignment operators include =, +=, -=, *=, and /=.
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments