+ 1
Trying to understand programming
How did the computer get this answer!? >>> x = 2 >>> print(x) 2 >>> x += 3 >>> print(x) 5
6 Respuestas
+ 3
x += 3 is shorthand for x = x + 3
Note that mathematically this wouldn't make sense, but in this case the equals sign is an assignment operator, and not an equality sign which is == in most programming languages.
+ 1
which bit dont you understand?
0
I don’t understand how the computer got 5?
0
@Xan will x= 2
0
Kareem Callwood
X= 2
X+=3 ( x = X(2) + 3 )
X = 5
0
ok x ends up = 5 because
firstly
you have set x = 2 so now x has the value of 2
as shown by printing it
when you do x + = 3
short for x = x + 3
which when you substitute the value of x in is
x = 2 + 3
which gives you the answer 5