## Python - Augmented Assignment Operators

CBSE Class 11 - Informatics Practices

Python provides augmented assignment operators, which combine the impact of an arithmetic operator with an assignment operator.

e.g. If you want to add value of b to a and then assign the result to a i.e.  a = a + b can be written as
a += b

Various augmented operators are:

OperationDescription
x += yx = x + y
x -= yx = x - y
x *= yx = x * y
x /= yx = x / y
x //= yx = x // y
x **= yx = x ** y
x %= yx = x % y
x &= yx = x & y
x |= yx = x | y
x ^= yx = x ^ y
x >>= yx = x >> y
x <<= yx = x << y

Q1: What is the output of the following code?
a, b = 10, 2
a += b
print(a)
a += b
print(a)

12
14

Q2: What is the output of the following code?
x = 10
x -= 6
print(x)
x -= 6
print(x)

4
-2

Q3: What is the output of the following code?
x, y = 2, 3
x **=y
print(x)
x **= y
print(x)

8
512

Q4: Does x += y violate mutability?

Answer: No. x += y creates a new object x storing result of x+y.

Informatics Syllabus (New) - 2019-20
Python Basics (Q & A)
Python Basics (Q & A) Part-2
Python Basics - Variables (Q & A)
Python Basics - Literals (Q & A)  