A doubt in the fourth Edition of python Learning Manual

I, a rookie, just started to learn Python. The example above on page 557 of Chapter 22 is shown below.

-sharp small.py
x = 1
y = [1,2]
-sharp new1.py
from small import x,y
x = 42
y[0] = 42
-sharp new2.py
import small
print(small.x)
print(small.y)

the execution result said in the book is

1
[42, 2]

but the test result on my own computer is

1
[1, 2]
Jul.06,2021

to achieve the effect in the book, you need to execute two pieces of code in the same session . If you perform the operations in new1.py in two sessions, of course, it will not affect the data in new2.py.

Menu