Informatics Practices

Give the output of the following when num1 = 4, num2 = 3, num3 = 2.

num1 += num2 + num3
print(num1)

Python Control Flow

2 Likes

Answer

9

Working

In the above code, num1 += num2 + num3 is a shorthand notation for num1 = num1 + num2 + num3.

Given,

num1 = 4
num2 = 3
num3 = 2

First, the expression num2 + num3 is evaluated:

num2 + num3 = 3 + 2 = 5

Now the expression becomes:

num1 = num1 + 5

which translates to:

num1 = 4 + 5 = 9

Answered By

3 Likes


Related Questions