Operators in Python


Operators are used to perform operations on variables and values.

  • Arithmetic operators
  • Assignment operators
  • Relational Operators
  • Logical operators
  • Bitwise operators

Arithmetic operators

It is used to perform arithmetic operation like Addition,Subtraction,multiplication,division and modulus.
Types of arithmetic operators is given below:-

Responsive image

Assignment operators

The word Assignment is stand for 'assign'+'ment' means "assign value to some variable".the value of right side which have same datatype to left side.
Types of assignment operators is given below:-

Responsive image

Relational Operators

This operator is used in comparison of the values of two operands.means suppose we have two number x=12 and y=13 we can apply (>,<,<=,>=,==,!=) if we compare x<y,then it return 1,if x>y,then it return 0.
Types of Relational operators is given below:-

Responsive image

Logical Operators

When we combine two or more Condition and implement original condition then we are use logical operater
Types of Logical operators is given below:-

Responsive image

Bitwise Operators

In C programming languages there are 6 bitwise operators and
types of Bitwise operators and its function are:-

and(&)

The bitwise AND operator is denoted by single ampersand: &. While performing the bitwise AND operation is 1 if both the bits have the value as 1; otherwise, the result is always 0.

Example

#include<stdio.h>
int main()
{
    int a=7,b=11;
    printf("%d & %d=%d",a,b,a&b);
}

Output

11

or(|)

The bitwise OR operator is denoted by: |. While performing the bitwise OR operation is 1 if any one of the bits have the value as 1; otherwise, the result is always 0.

Example

#include<stdio.h>
int main()
{
  int a=7,b=11;
  printf("%d | %d=%d",a,b,a|b);
}

Output

15

bitwise not(~)

The bitwise NOT operator is denoted by: '~'. While performing the bitwise NOT operation is 1 if bit is 0; otherwise, the result is always 0.

Example

#include<stdio.h>
int main()
{
  int a=7;
  printf("~%d=%d",a,~a);
}

Output

~7=248

Right shift(>>)

The bitwise Right Shift operator is denoted by: '>';, and when two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.

Example

#include<stdio.h>
int main()
{
    int a=7;
    printf("%d >>1=%d",a,a>>1);
}
  

Output

7>>1=5

Left shift(<<)

The bitwise Left shift operator is denoted by: <, and when two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift.

Example

#include<stdio.h>
int main()
{
  int a=7;
  printf("%d <<1=%d",a,a<<1);
}

Output

7<<1=22