You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quoting from https://docs.python.org/3/c-api/long.html
463
-
>The current implementation keeps an array of integer objects forall integers between -5and256, when you create an intin that range you just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behavior of Python, in this case, is undefined. :-)
@@ -481,9 +481,9 @@ Quoting from https://docs.python.org/3/c-api/long.html
481
481
140084850247344
482
482
```
483
483
484
-
Here the interpreter isn't smart enough while executing `y = 257` to recognize that we've already created an integer of the value `257,`and so it goes on to create another objectin the memory.
**Both`a`and`b`refer to the same object when initialized with same value in the same line.**
486
+
**当`a`和`b`在同一行中使用相同的值初始化时,会指向同一个对象.**
487
487
488
488
```py
489
489
>>> a, b = 257, 257
@@ -499,8 +499,8 @@ Here the interpreter isn't smart enough while executing `y = 257` to recognize t
499
499
140640774013488
500
500
```
501
501
502
-
*When a and b are set to `257`in the same line, the Python interpreter creates a new object, then references the second variable at the same time. If you do it on separate lines, it doesn't "know" that there's already `257`as an object.
503
-
*It's a compiler optimization and specifically applies to the interactive environment. When you enter two lines in a live interpreter, they're compiled separately, therefore optimized separately. If you were to try this example in a `.py`file, you would not see the same behavior, because the fileis compiled all at once.
502
+
*当 a 和 b 在同一行中被设置为 `257`时, Python 解释器会创建一个新对象, 然后同时引用第二个变量. 如果你在不同的行上进行, 它就不会 "知道" 已经存在一个 `257`对象了.
0 commit comments