Different Types of Operators in Python

Python Operators in general are used to perform operations on values and variables. These are standard symbols used for the purpose of logical and arithmetic operations. In this post, we will look into different types of Python operators...

Different Types of Operator in Python

1. Arithmetic Operators: Arithmetic operators are used to performing 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 the first operand is divided by the secondx % y
**Power: Returns first raised to power secondx ** y

2. Comparison Operators: Comparison of Relational operators compares the values. It either returns True or False according to the condition...

OperatorDescriptionSyntax
>Greater than: True if the left operand is greater than the rightx > y
<Less than: True if the 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 the left operand is greater than or equal to the rightx >= y
<=Less than or equal to True if the left operand is less than or equal to the rightx <= y

3. Logical Operators: Logical operators perform Logical AND, Logical OR, and Logical NOT operations. It is used to combine conditional statements...

OperatorDescriptionSyntax
andLogical AND: True if both the operands are truex and y
orLogical OR: True if either of the operands is true x or y
notLogical NOT: True if the operand is false not x

4. Bitwise Operators: Bitwise operators act on bits and perform the bit-by-bit operations. These are used to operate on binary numbers...

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

5. Assignment Operators: Assignment operators are used to assigning values to the variables...

OperatorDescriptionSyntax
=Assign value of right side of expression to left side operand x = 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 the 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

6. Identity Operators: "is" and "is not" are the identity operators both are used to check if two values are located on the same part of the memory. Two variables that are equal do not imply that they are identical...

is		True if the operands are identical 
not is		True if the operands are not identical

7. Membership Operators: "in" and "not in" are the membership operators; used to test whether a value or variable is in a sequence...

in            True if value is found in the sequence
not in        True if value is not found in the sequence

Previous Post Next Post