Python Operators:


There are following types of operators in Python
  1. Arithmetic Operators
  2. Comparision Operators
  3. Logical (or Relational) Operators
  4. Assignment Operators
  5. Conditional (or ternary) Operators



Arithmetic Operators


Operator Description
+Addition - Adds values on either side of the operator
-Subtraction - Subtracts right hand operand from left hand operand
*Multiplication - Multiplies values on either side of the operator
/Division - Divides left hand operand by right hand operand
%Modulus - Divides left hand operand by right hand operand and returns remainder
**Exponent - Performs exponential (power) calculation on operators
//Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed.



Comparison Operators


Operator Description
== Checks if the value of two operands are equal or not, if yes then condition becomes true
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true
<> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true
>=Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true



Logical Operators


OperatorDesdription
andCalled Logical AND operator. If both the operands are true then then condition becomes true.
orCalled Logical OR Operator. If any of the two operands are non zero then then condition becomes true.
notCalled Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.



Assignment Operators


Operator Description
=Simple assignment operator, Assigns values from right side operands to left side operand
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
**= Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand
//= Floor Dividion and assigns a value, Performs floor division on operators and assign value to the left operand



a = 20
if ( a  == 20 ) : print "Value of expression is 20"
else: print "Good bye!"


In the next chapter you are going to learn dicision-making in python


Quantitative Aptitude
Reasoning
Programming
Interview