Python Operators
Doing some operations on values that is through operator.operator is a symbol which is do some operations on values and gives the output.
The values are known as Operands.
- Operand operations(+,-,*,/) operand output operation(=) operand
Like:
1 + 2 = 3
- Here 1 and 3 are Operands and + (plus) ,= (equal) signs are the operators. They generate the output 9.
Python have some operators :
Let's know about python operators..
List of operators :
1) Arithmetic Operators.
2) Relational Operators.
3) Assignment Operators.
4) Logical Operators.
5) Membership Operators.
6) Identity Operators.
7) Bitwise Operators.
Let's know about in detail....
1) Arithmetic Operators:
- // (Double forward slash sign) It Perform Floor division(gives integer value after division)
Like :
5 // 2 = 2
- + (Plus sign) It is use to perform an addition.
Like :
5 + 2 = 7
- - (Minus sign) It is use to perform subtraction
Like :
5 - 2 = 3
- * (star sign) It is use to perform multiplication.
Like :
5 * 2 = 10
- / (single forward slash sign) It is use to perform division
Like :
5 / 2 = 2.5
- % (Modulus sign) To return remainder after division(Modulus)
Like :
10 % 3 = 1
- ** (Two star sign) It is use to perform exponent(raise to power)
Like :
3**3 = 27
2) Relational Operators :
- < Less than :
Like :
1<2
Output : True
- > Greater than :
Like :
1<2
Output : False
- <= Less than or equal to :
Like :
1<=1
Output : True
- >= Greater than or equal to :
Like :
10>=5
Output : True
- == Equal to :
Like :
1<2
Output : False
- != Not equal to :
Like :
1!=2
Output : True
- < > Not equal to(similar to !=) :
Like :
1< >2
Output : True
3) Assignment Operators :
- = Assignment :
Like :
a = 10
print a
Output : 10
- /= Divide and Assign :
Like :
a=10
a/=2
Output : 5
- += Add and assign :
Like :
a=10
a+=2
Output : 12
- -= Subtract and Assign :
Like :
a=10
a-=2
Output : 8
- *= Multiply and assign :
Like :
a=10
a*=2
Output : 20
- %= Modulus and assign :
Like :
a=10
a%=3
Output : 1
- **= Exponent and assign :
Like :
a=5
a**=2
Output : 25
- //= Floor division and assign
Like :
a=25
a//=2
Output : 12
4) Logical Operators:
- and : Logical AND(When both conditions are true output will be true)
- or : Logical OR (If any one condition is true output will be true)
- not : Logical NOT(Compliment the condition i.e., reverse)
5) Membership Operators:
- in : Returns true if a variable is in sequence of another variable, else false.
- not in : Returns true if a variable is not in sequence of another variable, else false.
6) Identity Operators :
- is : Returns true if identity of two operands are same, else false
- is not : Returns true if identity of two operands are not same, else false.