Operators in Python

\operators are used to perform various operators in every programming language.

operator is a symbol to perform task,operands are values

  1. Arithmetic Operators
  2. Comparison Operators
  3. Assignment Operators
  4. Logical Operators
  5. Bitwise Operators

Arithmetic Operators

arithmetic operations are performed using arithmetic operators, arithmetic operations like addition, subtraction and division are performed

+Addition operator22+22=44
-Subtraction operator10-6=4
*Multiplication operator10*2=20
/Float Division Operator10/2=2.0
//Integer Division Operator10//2=2
%Remainder Operator10/2=5
**Exponentiation Operator2**3=8

float division operator( / ):this operator returns remainder of two operands in float format (decimals), example is given below


Integer Division Operator (//): this operator returns remainder of two operands in integer format, an example is given below


Comparison Operators

comparison operators are also know as Relational operators,these will retrun in output in the Boolean value like True or False

OperatorDescriptionExampleReturn Value
Smaller than4True
>Greater than2>7False
Smaller than or equal to4True
>=Greater than or equal to10>=2True
!=Not equal to5!=5False
!ERROR! unexpected operator '='equal to6==6True

Assignment Operators

OperatorExampleEquivalent Statement
+=x += 10x = x + 10
-=x -=10x = x - 10
*=x *= 10x = x * 10
/=x /= 10x = x / 10
//=x //= 10x = x // 10
%=x %= 10x = x % 10
**=x **= 10x = x ** 10

any operator preceding assignment operator are modified ,and performed a specific operation

Logical Operators

logical operators are used compare two Boolean values , Expressions containing logical operators are known as Logical expressions

andx and yTrue if both sides of the operator is True
orx or yTrue if either of the operand is True
notnot xComplements the operand

Bitwise Operators

Last updated on by vishal devxo