python shell 和 eclipse 执行结果不一样

总结如下:
python shell 执行结果为:
python shell 和 eclipse 执行结果不一样



eclipse for python(PyDev) 执行结果为:
python shell 和 eclipse 执行结果不一样



把代码写进脚本test.py 执行结果为:
python shell 和 eclipse 执行结果不一样



结论如下:python shell 是 输入一行,计算一行的,因为每回车一次,相当于执行了一次,所以 a 和 b 地址不一样,相当于执行了多个程序,而脚本文件和 eclipce 是先定义完整的代码块,只执行一次,所以 a 和 b 分配的地址是一样的,为了验证,可以在python shell 里面,把所有代码写进一行执行,发现确实和 eclipse ,脚本文件test.py 结果一样:
python shell 和 eclipse 执行结果不一样