Question

Are all references variables and all variables references in Python?

Obviously there's a difference between a variable and a reference in e.g. C++ but what about Python?

Was it helpful?

Solution

Although even Python documentation mixes the terms, the reference documentation uses the terms identifiers or names instead of variables. It's the same concept though.

All identifiers are references; all values in Python are objects whose lifetime is governed by how many references exist to those objects; objects whose reference count drops to 0 are cleaned up.

However, not all references are identifiers. List indices are also references, as are the keys and values in a dictionary, and the attributes on an object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top