# Assignment Operators in Python

• Difficulty Level : Basic
• Last Updated : 29 Aug, 2020

Operators are used to perform operations on values and variables. These are the special symbols that carry out arithmetic, logical, bitwise computations. The value the operator operates on is known as Operand.

Here, we will cover Assignment Operators in Python. So, Assignment Operators are used to assigning values to variables.

Now Let’s see each Assignment Operator one by one.

1) Assign: This operator is used to assign the value of the right side of the expression to the left side operand.

Syntax:

```x = y + z
```

Example:

## Python3

 `# Assigning values using  ` `# Assignment Operator ` ` `  `a ``=` `3` `b ``=` `5` ` `  `c ``=` `a ``+` `b ` ` `  `# Output ` `print``(c)`

Output:

```8
```

2) Add and Assign: This operator is used to add the right side operand with the left side operand and then assigning the result to the left operand.

Syntax:

```x += y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a + b ` `a ``+``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```8
```

3) Subtract and Assign: This operator is used to subtract the right operand from the left operand and then assigning the result to the left operand.

Syntax:

`x -= y`

Example –

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a - b ` `a ``-``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```-2
```

4) Multiply and Assign: This operator is used to multiply the right operand with the left operand and then assigning the result to the left operand.

Syntax:

```x *= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a * b ` `a ``*``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```15
```

5) Divide and Assign: This operator is used to divide the left operand with the right operand and then assigning the result to the left operand.

Syntax:

```x /= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a / b ` `a ``/``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```0.6
```

6) Modulus and Assign: This operator is used to take the modulus using the left and the right operands and then assigning the result to the left operand.

Syntax:

```x %= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a % b ` `a ``%``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```3
```

7) Divide (floor) and Assign: This operator is used to divide the left operand with the right operand and then assigning the result(floor) to the left operand.

Syntax:

```x //= y
```

Example:

## Python

 `a ``=` `3` `b ``=` `5` ` `  `# a = a // b ` `a ``/``/``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```0
```

8) Exponent and Assign: This operator is used to calculate the exponent(raise power) value using operands and then assigning the result to the left operand.

Syntax:

```x **= y
```

Example:

## Python

 `a ``=` `3` `b ``=` `5` ` `  `# a = a ** b ` `a ``*``*``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```243
```

9) Bitwise AND and Assign: This operator is used to perform Bitwise AND on both operands and then assigning the result to the left operand.

Syntax:

```x &= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a & b ` `a &``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```1
```

10) Bitwise OR and Assign: This operator is used to perform Bitwise OR on the operands and then assigning result to the left operand.

Syntax:

```x |= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a | b ` `a |``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```7
```

11) Bitwise XOR and Assign: This operator is used to perform Bitwise XOR on the operands and then assigning result to the left operand.

Syntax:

```x ^= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a ^ b ` `a ^``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```6
```

12) Bitwise Right Shift and Assign: This operator is used to perform Bitwise right shift on the operands and then assigning result to the left operand.

Syntax:

```x >>= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a >> b ` `a >>``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```0
```

13) Bitwise Left Shift and Assign: This operator is used to perform Bitwise left shift on the operands and then assigning result to the left operand.

Syntax:

```x <<= y
```

Example:

## Python3

 `a ``=` `3` `b ``=` `5` ` `  `# a = a << b ` `a <<``=` `b ` ` `  `# Output ` `print``(a)`

Output:

```96
```

My Personal Notes arrow_drop_up
Recommended Articles
Page :