 # Python Operators: Types of Operators in Python With Examples

Here in this blog, you will know about the python operators and also the operators types in detail. And you will get the proper knowledge about how to use the python operators because we will tell you all about the python operators and types of operators in python with example.

Students often get their python operators assignment from college, and they always face many issues, so they always prefer to hire experts for python homework help, but we are here to provide you complete detail about python operators so that you can do your python assignment by itself.

## What are Operators in Python?

Operators are the special symbols that are used to carry out logical, arithmetic or bitwise computations. To assign a value to a variable operators are used. And the operator operates on the value which is called the operand.

## Types of Operators in Python with Example

Here, we will cover all Python operators with examples and also the shorthand assignment operators in python with the help of python operators examples. There are many types of python operators, which are shown below in detail.

### Arithmetic Operators

To perform mathematical operations such as addition, subtraction, multiplication, etc, arithmetic operators are used.

#### Example : Arithmetic operators in Python

``````a = 16
b = 4

# Output: a * b = 64
print('a * b =',a*b)

# Output: a - b = 12
print('a - b =',a-b)

# Output: a / b = 4
print('a / b =',a/b)

# Output: a + b = 20
print('a + b =',a+b)

# Output: a ** b = 65536
print('a ** b =',a**b)``````

Output

``````a * b = 64
a - b = 12
a / b = 4
a + b = 20
a ** b = 65536
``````

### Comparison Operators

Comparison operators are used to comparing the values. And according to the conditions, it returns either True or False.

#### Example : Comparison operators in Python

``````a = 7
b = 11

# Output: a < b is True
print('a < b is',a<b)

# Output: a == b is False
print('a == b is',a==b)

# Output: a > b is False
print('a > b is',a>b)

# Output: a <= b is True
print('a <= b is',a<=b)

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

# Output: x >= y is False
print('a >= b is',a>=b)``````

Output

``````a < b is True
a == b is False
a > b is False
a <= b is True
a != b is True
a >= b is False
``````

### Logical Operators

In Python And, Or, Not are the logical operators. And it gives the output / result in the form of True or False.

#### Example : Logical Operators in Python

``````a = True

b = False

print('not a is',not b)
print('a or y is',a or b)

print('a and b is',a and b)``````

Output

``````not a is False
a or b is True
a and b is False
``````

### Bitwise Operators

Bitwise operators mainly work on operands because binary digits are their strings. They perform bit by bit, hence the name.

See also  Python vs Perl | What are The Differences Between These Languages?

For example, 7 is 111 in binary digit.

The table shown below:

Let x=10 (0000 1010 in binary) and y=4 (0000 0100 in binary)

### Assignment Operators

In Python, to assign the values to variable assignment operators are used. There are various assignment operators in the Python, which are shown below in the table:

### Assign Operator

``````# Assigning values using
# Assignment Operator

a = 2
b = 4

c = a + b

# Output
print(c)
``````

Output

``c = 6``

#### Examples of Other Assignment Operators in Python

``````a = 2
b = 4

# Output: a + b = 6
print('a += b',a+b)

# Output: a - b = -2
print('a -= b',a-b)

# Output: a * b = 8
print('a *= b',a*b)

# Output: a / b = 0.5
print('a /= b',a/b)

# Output: a % b = 2
print('a %= b',a%b)

# Output: a // b = 0
print('a //= b',a//b)

# Output: a ** b = 16
print('a **= b',a**b)

# Output: a &= b = 0
print('a &= b',a&b)

# Output: a |= b = 6
print('a |= b',a|b)

# Output: a ^= b = 6
print('a ^= b',a^b)

# Output: a >>= b = 0
print('a >>= b',a>>b)

# Output: a <<= b = 32
print('a <<= b',a<<b)``````

Output

``````a += b : 6
a -= b : -2
a *= b : 8
a /= b : 0.5
a %= b : 2
a //= b : 0
a **= b : 16
a &= b : 0
a |= b : 6
a ^= b : 6
a >>= b : 0
a <<= b : 32
``````

### Special Operators

There are some special types of operators in the python language, such as the identity operator or the membership operator, which are shown below:

See also  What is SQL software And How Sequel Programming Languages Different

### Identity Operators

The identity operators in the python language are the “is” and “is not”. These are used when there are two variables/values that are located on the same memory part. And also, the two equal variables do not imply that they are identical.

Example : Identity operators in Python

``````a1 = 8
b1 = 8
a2 = 'Heya'
b2 = 'Heya'
a3 = [1,2,3]
b3 = [1,2,3]

# Output: False
print(a1 is not b1)

# Output: True
print(a2 is b2)

# Output: False
print(a3 is b3)``````

Output

``````False
True
False
``````

### Membership Operators

The membership operators in the python language are the “in” and “not in”. These are utilized to test whether a value or variable is found in a sequence (dictionary, set, list, tuple, and string).

Example : Membership operators in Python

``````a = 'Hello'
b = {1:'x',2:'y'}

# Output: True
print('H' in a)

# Output: True
print('hello' not in a)

# Output: True
print(1 in b)

# Output: False
print('x' in b)
``````

Output

``````True
True
True
False
``````