In this article, you will learn all about Python assignment operators with the help of examples. If you are a Python developer, Then you can’t ignore operators in Python because Python operators are very useful to perform different types of operations on value or variables.

In our previous Python tutorials, we have seen different types of Python operators with the help of the exmaples.

Without any wasting time, let’s understand Python assignment operators with the help of the examples.

Headings of Contents

- 1 Python Assignment Operators
- 1.1 Assign
- 1.2 Add and Assign
- 1.3 Subtract and Assign
- 1.4 Multiply and Assign
- 1.5 Divide and Assign
- 1.6 Modulus and Assign
- 1.7 Floor and Assign
- 1.8 Exponent and Assign
- 1.9 Bitwise AND and Assign
- 1.10 Bitwise OR and Assign
- 1.11 Bitwise XOR and Assign
- 1.12 Bitwise Right shift and Assign
- 1.13 Bitwise left shift and Assign

- 2 Conclusion

## Python Assignment Operators

Assignment operators in Python are very useful and commonly used operators, Basically they are used to assign the value to the variables. There are various types of assignment operators available in Python.

**Type of Assignment operators**:

**Assign****Add and assign****Subtract and assign****Multiply and assign****Divide and assign****Modulus and Assign****Floor and Assign****Exponent and Assign****Bitwise AND and Assign****Bitwise OR and Assign****Bitwise XOR and Assign****Bitwise Right shift and Assign****Bitwise Left shift and Assign**

**Python** **Assignments Operators Table**

Operator | Example | Same As |
---|---|---|

= | x=y | x=y |

+= | x+=y | x=x+y |

-= | x-=y | x =x-y |

*= | x*=y | x = x * y |

/= | x/=y | x = x / y |

//= | x//=y | x = x // y |

**= | x**=y | x = x ** y |

%= | x%=y | x = x % y |

<<= | x<<=y | x = x <<= y |

>>= | x>>=y | x >>= y |

&= | x &= y | x = x&y |

^= | x^=y | x = x ^ y |

|= | x |=y | x = x | y |

### Assign

This operator is used to assign the right side of the expression to the left side of the operand.

**Example**

```
a, b = 12, 20
result = a + b
print("The result is:- ", result)
```

### Add and Assign

This operator is used to add right side of the expression to the left side operand and assign the result to the left side operand.

**Example**

```
a = 12, b = 20
a += b
print("The result is:- ", a)
```

### Subtract and Assign

This operator is used to subtract right side of the expression to the left side operand and assign the result to the left side operand.

**Example**

```
a, b = 12, 20
a -= b
print("The result is:- ", a)
```

### Multiply and Assign

This operator is used to multiply the right side of the operand to the left side of the operand and then assign the result to the left side operand.

**Example**

```
a, b = 12, 20
a *= b
print("The result is:- ", a)
```

### Divide and Assign

This operator is used to divide the the left operand to the right operand and assign the result to the left operand.

**Example**

```
a, b = 120, 20
a /= b
print("The result is:- ", a)
```

### Modulus and Assign

This operator is used to divide the left operand to the right operand and and then assign the modulus to the left operand.

**Example**

```
a, b = 150, 20
a %= b
print("The result is:- ", a)
```

### Floor and Assign

This operator is used to divide the left operand to the right operand and and then assign the result (floor) to the left operand.

**Example**

```
a , b = 125, 20
a //= b
print("The result is:- ", a)
```

### Exponent and Assign

This operator is used to calculate the exponent and using operands and assign the result to the left operand.

**Example**

```
a, b = 125, 20
a **= b
print("The result is:- ", a)
```

### Bitwise AND and Assign

This operator basically used to apply bitwise AND operation on both operand and assign the result to the left operand.

**Example**

```
a, b = 125, 20
a &= b
print("The result is:- ", a)
```

### Bitwise OR and Assign

This operator basically used to appy bitwise OR opertion on both operand and assign the result to the left operand.

**Example**

```
a, b = 125, 20
a |= b
print("The result is:- ", a)
```

### Bitwise XOR and Assign

This operator basically used to apply bitwise XOR operation on both operand and assign the result to the left operand.

**Example**

```
a, b = 125, 20
a ^= b
print("The result is:- ", a)
```

### Bitwise Right shift and Assign

This operator basically used to Bitwise Right shift and Assign operation on operands and assign the result to the left operand.

**Example**

```
a, b = 125, 20
a >>= b
print("The result is:- ", a)
```

### Bitwise left shift and Assign

This operator basically used to Bitwise Right left and Assign operation on operands and assign the result to the left operand.

**Example**

```
a, b = 20, 2
a <<= b
print("The result is:- ", a)
```

## Conclusion

So, In this article, we have seen all about Python assignment operators and types with the help of examples. Assignment operators in **Python **will be very useful when you are going to perform some operations and then assign results to the variables.

I hope this article will help you. if you like this article, please share and keep visiting for further **Python tutorials**.

**Python Operators **

**Thanks for reading**