Python Operators

 Operators In Python

What is operators in python?

Python operators are special symbols, used to perform operations on variables and values. It is classified in the following groups :
  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators 
  • Identity operators
  • Membership operators

Python Arithmetic Operators

Arithmetic operators allows to perform common mathematics operations on numeric values. following are arithmetic operators :

  •  +  Addition : Used to add two or more values.
  •  -  Subtraction : Used to subtract values.
  •   Multiplication : Used to multiply value.
  •  /  Division : Used to divide values. It always gives the output as float value.
  •  //  Floor division : Also used to divide values but It doesn't gives the output as float values.
  •  %  Modules : Used to find the remainder of division.
  •  **  Exponentiation : It allows to make the one value as exponent for another values. and used to find square, cube, etc of a value.

Example of all arithmetic operators are shown in picture.



Python Assignment Operators

Assignment operators are help to assign values in variables. These are similar to arithmetic operators. It always assign given values to the left side variable. Following are assignment operators :

  •  =  : Equal
  •  +=  : Addition
  •  -=  : Subtraction
  •  *=  : Multiplication
  •  /=  : Division
  •  //=  : Floor division
  •  %=  : Modules
  •  **=  : Exponentiation
  •  >>=  : Bitwise Right-shift
  •  <<=  : Bitwise Left-shift
  •  &=  : Bitwise And

  •  |=  : Bitwise Or
  •  ^=  : Bitwise xOR

 
Example of all assignment operators are shown in picture.





Python Comparison Operators

comparison operators allow to compare two values. Following are comparison operators :

  •  ==  : To show that two values are equal.
  •  !=  : To show that values are not equal.
  •  <  : To show that one value is less than the other.
  •  <=  : To show that one value is less than or equal to the other.
  •  >  : To show that one value is grater than the other.
  •  >=  : To show that one value is grater than or equal to other.

Example of all comparison operators are shown in picture.



Python Logical Operators

Logical operators allow to combine two conditional statements. Following are logical operator :

  •  and  : When the both statements are true then it returns True. In other cases, it always returns False.
  •  or  : When one statement is true then it return True. In other cases, It always returns False.
  •  not  : It always return opposite result of the statement.


Example of all logical operators are shown in picture.



Python Identity Operators

Identity operators identify the variable that the two variable are same or notFollowing are identity operators :

  •  is  : When the both variables are same then it returns True.
  •  is not  : When the both variable are not same then it returns True.

Example of all identity operators are shown in picture.



Python Membership Operators

Membership operators are used to find the presence of member in a sequence.

  •  in  : When the member present in the sequence then it return True.
  •  not in  : When the member not present in the sequence then it return True.

Example of all membership operators are shown in picture.




Which operator do you use the most? Tell me in the comment section.

Comments