Operator Practice Program ( DS150423 )

What is the output of the following :

y = 10
x = y += 2
print (x)

1 Like

What is the output of the following :

y = 10
x = y += 2
print (x)

x=12

y = 10
x =y+=2
print(x)
x = 12

y=10
x=y+=2
print(x)
x=12

y = 10
x =y+=2
print(x)
ANS: It throws an error because of invalid syntax (x can’t be assigned y+=2)

y=10
x= y++2
print(x)
Then the answer will be 12

or

y=10
y+=2
x=y
print(x)
Then the answer will be 12

y = 10
x = y += 2
print(x)
#output: invalid syntax

#correct code

y = 10
y += 2
x = y
print(x)
#output:12

y=10
x=y+=2
print(x)

x=12

y=10
y+=2
x=y
print(x)
12

y=10
x=y+=2
print(x)
#syntaxerror:invalid syntax:-output
y=10
y+=2
x=y
print(x)
output:-12

y=10
x=y+=2
print(x)

The value of x will be 12

y = 10
x = y += 2
print (x)

o\p :
x = y += 2
^
SyntaxError: invalid syntax

Correction :

y=10
y+=2
x=y
print(x)

o\p :
12