Discuss / Python / 为什么不是-8

为什么不是-8

Topic source

宋洪基

#1 Created at ... [Delete] [Delete and Lock User]
初始值 balance = 0

t1: x1 = balance + 5  # x1 = 0 + 5 = 5

t2: x2 = balance + 8  # x2 = 0 + 8 = 8
t2: balance = x2      # balance = 8

t1: balance = x1      # balance = 5
t1: x1 = balance - 5  # x1 = 5 - 5 = 0
t1: balance = x1      # balance = 0

t2: x2 = balance - 5  # x2 = 0 - 5 = -5
t2: balance = x2      # balance = -5

结果 balance = -5

上面代码倒数第三行难道不应该是-8,最后结果不应该是-8吗?

笔误吧,-8没错。


  • 1

Reply