Python Operator

operator in python

The Python Operator can be defined as a symbol which is responsible for a particular operation between two operands. Python Operator are the pillars of a program on which the logic is built in a specific programming language. Python provides a variety of Python Operator, which are described as follows.

  • Arithmetic operators
  • Comparison operators
  • Assignment Operators
  • Logical Operators
  • Bitwise Operators
  • Membership Operators
  • Identity Operators

Arithmetic operators: 

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division.

OPERATORDESCRIPTIONSYNTAX
+Addition: adds two operandsx + y
Subtraction: subtracts two operandsx – y
*Multiplication: multiplies two operandsx * y
/Division (float): divides the first operand by the secondx / y
//Division (floor): divides the first operand by the secondx // y
%Modulus: returns the remainder when first operand is divided by the secondx % y
**Power : Returns first raised to power secondx ** y

Relational Operators:

 Relational operators compares the values. It either returns True or False according to the condition.

OPERATORDESCRIPTIONSYNTAX
Greater than: True if left operand is greater than the rightx > y
Less than: True if left operand is less than the rightx < y
==Equal to: True if both operands are equalx == y
!=Not equal to – True if operands are not equalx != y
>=Greater than or equal to: True if left operand is greater than or equal to the rightx >= y
<=Less than or equal to: True if left operand is less than or equal to the rightx <= y

Logical operators:

 Logical operators perform Logical ANDLogical OR and Logical NOT operations.

OPERATORDESCRIPTIONSYNTAX
andLogical AND: True if both the operands are truex and y
orLogical OR: True if either of the operands is truex or y
notLogical NOT: True if operand is falsenot x

Bitwise operators:

 Bitwise operators acts on bits and performs bit by bit operation.

OPERATORDESCRIPTIONSYNTAX
&Bitwise ANDx & y
|Bitwise ORx | y
~Bitwise NOT~x
^Bitwise XORx ^ y
>> Bitwise right shiftx>>
<< Bitwise left shiftx<<

Assignment operators: 

Assignment operators are used to assign values to the variables.

OPERATORDESCRIPTIONSYNTAX
=Assign value of right side of expression to left side operandx = y + z
+=Add AND: Add right side operand with left side operand and then assign to left operanda+=b     a=a+b
-=Subtract AND: Subtract right operand from left operand and then assign to left operanda-=b       a=a-b
*=Multiply AND: Multiply right operand with left operand and then assign to left operanda*=b       a=a*b
/=Divide AND: Divide left operand with right operand and then assign to left operanda/=b         a=a/b
%=Modulus AND: Takes modulus using left and right operands and assign result to left operanda%=b   a=a%b
//=Divide(floor) AND: Divide left operand with right operand and then assign the value(floor) to left operanda//=b       a=a//b
**=Exponent AND: Calculate exponent(raise power) value using operands and assign value to left operanda**=b     a=a**b
&=Performs Bitwise AND on operands and assign value to left operanda&=b     a=a&b
|=Performs Bitwise OR on operands and assign value to left operanda|=b         a=a|b
^=Performs Bitwise xOR on operands and assign value to left operanda^=b       a=a^b
>>=Performs Bitwise right shift on operands and assign value to left operanda>>=b     a=a>>b
<<=Performs Bitwise left shift on operands and assign value to left operanda <<= b                    a= a << b

Recommended Posts:

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *