Python - Operators

Operators:

Operators are special symbols that carry out arithmetic or logical or any other computation.

Types of Operators:

1.Arithmetic operator:

Used to perform mathematical operations like addition, subtraction and so on.


Operator
Description
Example
Output
+
Addition
a=5
b=5
print(a+b)

10
-
Subtraction
a=5
b=5
print(a-b)

0
*
Multiplication
a=5
b=5
print(a*b)

25
/
Division
a=5
b=5
print(a/b)

1
%
Modulo
a=5
b=5
print(a%b)
0

2.Floor division operator: 

This operator is similar to the division operator. It is used to display the nearest whole number. Using double slash operator "\\".

Example:


print('7/5 value is',7/5)

print('7//5 value is',7//5)

 Output:
3.Power operator:


This operator is similar to the multiplication operator. It is used to display the power values.

Example: 2**5


Output:   32

4.Assignment operator:

An assignment operator is used to set the values or doing some computations.


Operator
Description
Example
Output
=
Assignment
a=10
b=a
print(a,b)

10
+=
Addition Assignment
a=5
a+=5
print(a)

10
-=
Subtraction Assignment
a=5
a-=5
print(a)

0
*=
Multiplication Assignment
a=5
a*=5
print(a)

25
/=
Division Assignment
a=5
a/=5
print(a)

1
%=
Modulo Assignment
a=5
a%5=5
0


5.Relational operator:

This operator also called a comparison operator. It is used to compare the values. It either returns True or False based on conditions.


Operator
Description
Example
Output
Greater then
a=10
b=5
print(a>b)

True
Less then
a=10
b=5
print(a<b)

False
>=
Greater then or equal
a=10
b=5
print(a>=b)

True

<=
Less then or equal
a=10
b=5
print(a<=b)

False
==
Equal
a=5
b=5
print(a==b)

True
!=
Not equal
a=5
b=10
print(a==b)

False
6.Logical operator:
The logical operators for AND, OR and NOT are used to combine simple relational statements into more complex expressions. 


Previous                                                     Next


Share:

No comments:

Post a Comment

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me