Arithmetic and Comparison Operators in Python
In this class, we discuss arithmetic and comparison operators in python.
For Complete YouTube Video: Click Here
Arithmetic Operators in Python
Arithmetic operators are those used to perform arithmetic operations like addition, subtraction, multiplication, etc.
Let’s take examples and understand the list of arithmetic operators present.
x=8 and y =5 are two variables considered in our example.
Addition: is an arithmetic operator performed with the symbol +
print(x+y) will display 13.
Subtraction: is an arithmetic operator performed with the symbol –
print(x-y) will display 3.
Multiplication: is an arithmetic operator performed with the symbol *
print(x*y) will display 40.
Division: is an arithmetic operator performed with the symbol /
print(x/y) will display 1.6.
Modulus: is an arithmetic operator performed with the symbol %. Modulus gives the reminder value after performing division.
print(x%y) will display 3.
Floor Division: is an arithmetic operator performed with the symbol //. floor division will consider the integer part after performing division.
print(x//y) will display 1.
Power: is an arithmetic operator performed with the symbol **.
print(x**y) will display 32768.
Comparison operators
Greater than: is a comparison operator performed with the symbol >.
Whenever a comparison is done. if the comparison is correct it will return true. otherwise false.
Comparison operators are returning Boolean type values which we already discussed in our previous class.
print(x>y) will display True.
Less Than: is a comparison operator performed with the symbol <.
print(x<y) will display False.
Equal to is a comparison operator performed with the symbol ==.
print(x==y) will display False.
Not Equal to: is a comparison operator performed with the symbol !=.
print(x!=y) will display True.
Greater than or equal to: is a comparison operator performed with the symbol >=.
print(x>=y) will display True.
Less than or equal to: is a comparison operator performed with the symbol <=.
print(x<=y) will display False.