Operators are symbols that tell the compiler to perform specific mathematical or logical manipulations. Python provides a variety of operators they are


  1. Arithmetic operators
  2. Relational Operators
  3. Assignment Operators
  4. Logical operators
  5. Identity operators
  6. Bitwise Operators
  7. Membership Operators


1. Arithmetic operators:


Arithmetic operations are used to perform mathematical operations.

+ (Addition) - It is used to add two operands.

- (Subtraction) - It is used to Subtracts right hand operand from left hand operand.

* (Multiplication) - It is used to multiply one operand with the other.

/ (divide) - It is used to Divide left hand side operand by right hand side operand.

% (Modulus) - It returns the reminder after dividing the first operand by the second operand.

** (Exponent) - It is used to Divides left hand operand by right hand operand and returns remainder.

// (Floor division) - Floor division returns the quotient(answer or result of division) in which the digits after the decimal point are removed. But if one of the operands(dividend and divisor) is negative, then the result is floored.


Eg:

a=10
b=20
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
print(a**b)

print(a//b)

OUTPUT:

30
-10
200
0.5
10
100000000000000000000
0

2. Assignment Operators:


Assignment operator is used to assign values to the variable. The list of assignment operators are.

(=) - It assigns the value from the right side operands to left side operands.(a=b+c)

(+=) - It adds right operand to the left operand and assign the result to left operand.(a+=b is equal to a=a+b )

(-=) - This operator subtract right operand from the left operand and assign the result to left operand.(a-=b is equal to a=a-b)

(*=) - This operator multiplies right operand from the left operand and assign the result to left operand.(a*=b is equal to a=a*b)

(/=) - This operator divides right operand from the left operand and assign the result to left operand.(a/=b is equal to a=a/b)

(%=) - This operator takes the two modulus and assign the result to left operand.(a%=b is equal to a=a%b)


3. Relational (Or) Comparison Operators


Comparison operator are used to compare two values. The list of Comparison are.

(==) - If the values of two operand are equal then the condition will become true.

(<) - If the left operand is less than the right operand then the condition will become true.

(>) - If the left operand is greater than the right operand then the condition will become true.

(<=) - If the left operand is less than or equal to right operand then the condition will become true.

(>=) - If the left operand is greater than or equal to the right operand then then the condition will become true.

(!=) - If the values of two operands are not equal then the condition will become true.


4. Logical operators


Logical operator are used to make decision. The list of logical operators are.

(AND) - If both the expression are true then the condition will become true.

(OR) - If any one of the expression is true the the condition will become true.

(NOT) - If an expression result is true, this operator will convert the result into false.

5. Identity operators


(is) - If both variables are same then it will return true.

(is not) - If both variables are not same then it will return true.

6. Bitwise Operators


Bitwise operator are used to compare binary numbers. The list of bitwise operators are.

$(AND) 

|(OR) 

^(XOR) 

~(NOT) 

<<(Left Shift) 

>>(Right Shift) 

7. Membership Operators


Membership operator are used to check the membership of value inside a python data structure.

(in) - If the first operand is found in the second operand then it will become true.

(not in) - If the first operand is not found in the second operand then it will become true.


Post a Comment

أحدث أقدم