# Python Operators: Logical, Arithmetic, Comparison with E.g.

In this operator in the python tutorial, you will learn everything about operators in Python with their syntax and how to use operators with operands.

## What is operators in python?

In Python programming, operators are used to performing operations on one and more operand and operand values.

## Types of Operators in Python

In Python programming, operators are divided into the following groups, which are given below:

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

### Arithmetic operators

The Python Arithmetic operators, which are used to perform mathematical operations like addition, subtraction, multiplication, Modulus, Floor division, and division.

#### Example of arithmetic operators

```x = 25
y = 6

# Output: x + y = 31
print('x + y =',x+y)

# Output: x - y = 19
print('x - y =',x-y)

# Output: x * y = 150
print('x * y =',x*y)

# Output: x / y = 4.16666
print('x / y =',x/y)

# Output: x // y = 4
print('x // y =',x//y)

# Output: x ** y = 244140625
print('x ** y =',x**y)
```

### Comparison operators

Python comparison operators, which are used to perform compare operations on operand values. This results in true and false returns.

#### Example of Comparison operators

```x = 25
y = 15

# Output: x > y is True
print('x > y  is',x>y)

# Output: x < y is False
print('x < y  is',x<y)

# Output: x == y is False
print('x == y is',x==y)

# Output: x != y is True
print('x != y is',x!=y)

# Output: x >= y is True
print('x >= y is',x>=y)

# Output: x <= y is False
print('x <= y is',x<=y)
```

### Assignment operators

Python Assignment operators, which are used to assign a value to the operand. Here operands mean variable.

#### Example of Assignment operators

```x = 5

# Output: x = 5
print(x)

# Output: x += 3 is 8
x += 3
print(x)

# Output: x -= 3 is 5
x -= 3
print(x)

# Output: x /= 3 is 1.6666
x /= 3
print(x)

a = 5

# Output: a <<= 3 is 40
a <<= 3
print(a)

# Output: a >>= 3 is 5
a >>= 3
print(a)

# Output: a ^= 3 is 6
a ^= 3
print(a)

# Output: a |= 3 is 7
a |= 3
print(a)

# Output: a &= 3 is 3
a &= 3
print(a)

# Output: a **= 3 is 27
a **= 3
print(a)

# Output: a //= 3 is 9
a//=3
print(a)

# Output: a %= 3 is 0
a%=3
print(a)
```

### Identity operators

Identity operators are used to comparing the objects, not if they are equal, but if they are actually the same object, with the same memory location.

#### Example Identity operators

```x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]

# Output: False
print(x1 is not y1)

# Output: True
print(x2 is y2)

# Output: False
print(x3 is y3)
```

### Logical operators

The Python logical operators, which are used to perform logical operations on operands.

#### Example of Logical operators

```x = True
y = False

# Output: x and y is False
print('x and y is',x and y)

# Output: x or y is True
print('x or y is',x or y)

# Output: not x is False
print('not x is',not x)

```

### Membership operators

Python membership operators, which are used to test whether a value or variable is in a sequence.

#### Example of Membership operators

```Result Size: 668 x 508
x = 'Hello world'
y = {1:'a',2:'b'}
​
# Output: True
print('H' in x)
​
# Output: True
print('hello' not in x)
​
# Output: True
print(1 in y)
​
# Output: False
print('a' in y)

```

### Bitwise operators

Python Bitwise operators, which are used perform the compare (binary numbers) operation on the operand. Here operands mean variable.

#### Example of Bitwise operators

```a = 10
b = 4

# bitwise AND operation
print(a & b)

# bitwise OR operation
print(a | b)

# bitwise NOT operation
print(~a)

# bitwise XOR operation
print(a ^ b)

# bitwise right shift operation
print(a >> 2)

# bitwise left shift operation
print(a << 2)

```