Back to questions
JuniorTheoryCommon
What does the program print?
x = 5
y = x
x = x + 1
print(x, y)6 5
- Expecting
6 6, as ifyfollowedx:y = xbindsyto the object5, andx = x + 1makes onlyxrefer to a new object6. - Expecting
x = x + 1to change nothing, read as an equation:=is assignment, so Python computesx + 1and bindsxto the result6.
- What does the program print if the third line is
x += 1instead? - What would
print(y)show if the liney = xcame afterx = x + 1?