3 ms·
How are name bindings different than references? >>> a=[2, 3, 1] >>> b=a >>> id(a) 139731931982216 >>> id(b) 139731931982216 >>> b
by dorfsmay 7y ago
How are name bindings different than references?
>>> a=[2, 3, 1]
>>> b=a
>>> id(a)
139731931982216
>>> id(b)
139731931982216
>>> b
[2, 3, 1]
>>> b.sort()
>>> del(b)
>>> a
[1, 2, 3]
>>>
- fulafel 7y agoDepends what you mean by reference. In Python they are indeed synonymous. C++ references are different in that the binding / object identity can be changed through the reference, eg when you pass a reference to a function.
- brudgers 7y agoIn Python, lists are container objects. Container objects reference other objects. In the first line object a references objects 2, 3 ,and 1 (and any other objects in a's object heritage). 2, 3 and 1 have id's. That's what "everything is an object" fleshes out to in Python. But they don't reference other objects because they are literals. The value of 2 is also its name.