Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
• Live Instructor-led Classes
• Expert Education
• 24*7 Support
• Flexible Schedule

Operators are the symbols which perform the operation on the some values. These values are known as operands. Python have following operators –

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

1. Arithmetic Operators

 Operator Operator Name Description Example + Addition Perform Addition I=40, J=20I+ J = 60 – Subtraction Perform Subtraction I=40, J=20I – J = 20 * Multiplication Perform Multiplication I=40, J=20I * J = 800 / Division Perform Division and display the I=30, J=20I /J = 2.5 % Modulus Return the remainder after Division I=40, J=20I /J = 0 ** Exponent Performs exponential (power) calculation I=40, J=20I /J = 20 to the power of 40 // Floor Division Perform division then remove the decimal value and return Quotient value I=30, J=20I//J = 1

2. Relational Operators

It is also known as comparison operator because it compares the values. After comparison it returns the Boolean value i.e. either true or false.

 Operator Operator Name Description Example == Equal to If the values of two operands are equal then then it returns true. I = 20, J = 20(I == J) is true != Not Equal to If the values of two operands are not equal then it returns true. I = 20, J = 20(I == J) is False < Less than If the value of left operand is less than the value of right operand then it returns true I = 40, J = 20(I < J) is False > Greater than If the value of left operand is greater than the value of right operand then it returns true I = 40, J = 20(I > J) is True <= Less than or equal to If the value of left operand is less than or equal to the value of right operand then it returns true. I = 40, J = 20(I <= J) is False >= Greater than or equal to If the value of left operand is greater than or equal to the value of right operand then it returns true. I = 40, J = 20(I >= J) is True <> Not equal to(similar to !=) If values of two operands are not equal then condition becomes true. I=40, J = 20(I <> J) is true. This is similar to != operator.

3. Assignment Operators

 Operator Operator Name Description Example = Assignment It assigns value from right side operand to left side operand I = 40It assigns 40 to I += Add then assign It performs addition and then result is assigned to left hand operand I+=J that meansI = I + J -= Subtract then assign It performs subtraction and then result is assigned to left hand operand I-=J that meansI = I – J *= Multiply the assign It performs multiplication and then result is assigned to left hand operand. I*=J that meansI = I * J /= Divide then assign It performs division and then result is assigned to left hand operand I/=J that meansI = I / J %= Modulus then assign It performs modulus and then result is assigned to left hand operand I%=J that meansI = I % J **= Exponent then assign It performs exponent and then result is assigned to left hand operand I**=J that meansI = I ** J //= Floor division then assign It performs floor division and then result is assigned to left hand operand I//=J that meansI = I // J

4. Logical Operators

 Operator Operator Name Description Example and Logical AND When Both side condition is true the result is true otherwise false 2<1 and 2<3False or Logical OR When at least one condition is true then result is true otherwise false 2<1 or 2<3True not Logical NOT Reverse the condition Not(5>4)False

5. Membership Operators

 Operator Description Example in It returns true if it finds a variable in the sequence otherwise returns false List = [1,2,3,4,5,6,7,8];i=1;If(i in List):print ‘i is available in list’Elseprint ‘i is not available in list’Output – i is available in list not in It returns true if it does not find a variable in the sequence otherwise returns false List = [1,2,3,4,5,6,7,8];j=10;If(j not in List):print ‘j is not available in list’Elseprint ‘j is available in list’Output – j is not available in list

6. Bitwise Operators

It performs bit by bit operation. Suppose there are two variable I = 10 and J = 20 and their binary values are

I = 10 = 0000 1010

J = 20 = 0001 0100

 Operator Operator Name Description Example & Binary AND If both bits are 1 then 1 otherwise 0 I & J0000 0000 | Binary OR If one of the bit is 1 then 1 otherwise 0 I | J0001 1110 ^ Binary XOR If both bit are same then 0 otherwise 1 I ^ J0001 1110 ~ Binary Complement If bit is 1 the make it 0 and if bit is 0 the make it 1 ~I1111 0101 << Binary Left Shift The left operands is moved left by the number of bits specified by the right operand. I << 2 will give 240 i.e. 1111 0000 >> Binary Right Shift The left operands is moved right by the number of bits specified by the right operand. I >> 2 will give 15 i.e. 1111

7. Identity Operators

These operators are used to compare the memory address of two objects.

 Operator Description Example is It returns true if both operand ‘s identity is same otherwise false I = 20J = 20If(I is J):print ‘I and J have same identity’Elserint ‘I and J have not same identity’Output – I and J have same identity is not It returns true if both operand ‘s identity is not same otherwise false I = 20J = 230If(I is not J):print ‘I and J have not same identity’Elseprint ‘I and J have same identity’Output – I and J have not same identity
Previous Next

#### Download Interview Questions asked by top MNCs in 2018?

Learn SQL in 16 hrs from experts

### "0 Responses on Python Operators"

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

## Sales Offer

• To avail this offer, enroll before 11th December 2018.
• This offer cannot be combined with any other offer.
• This offer is valid on selected courses only.
• Cashback will be accumulated in Intellipaat e-wallet
• Please use coupon codes mentioned below to avail the offer