Reputation: 51
Most Python textbooks and introductory tutorials I have seen say that
The result of every expression is some object.
But I have also seen several Python sources that say that
The result of every expression is a reference to some object.
After some googling, I came to the conclusion that the second quote is true for CPython if we treat the term "reference" as a "PyObject*
pointer". As this post says (in the context of CPython):
Python's runtime only deals in references to objects (which all live in the heap): what goes on Python's stack (as operands and results of its bytecode operations) are always references (to values that live elsewhere).
My question is this: can we say that the phrase "the result of every expression is a reference to some object" is true in the Python language in general?
(i.e., can we say that this phrase is not just a CPython implementation detail, it is true for every Python implementation; of course, the specification of the term "reference" depends on the implementation)
And, if the answer is yes, why do most textbooks just say "the result of every expression is some object"? (i.e. they don't talk about references)
Upvotes: 1
Views: 46