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.
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:
Output:
3.Power operator:
This operator is similar to the multiplication operator. It is used to display the power values.
Example: 2**5
4.Assignment operator:
An assignment operator is used to set the values or doing some computations.
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.
6.Logical operator:
The logical operators for AND, OR and NOT are used to combine simple relational statements into more complex expressions.
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
|
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)
3.Power operator:
This operator is similar to the multiplication operator. It is used to display the power values.
Example: 2**5
Output: 32
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
|
The logical operators for AND, OR and NOT are used to combine simple relational statements into more complex expressions.
No comments:
Post a Comment