Search code examples
pythonvariablesprogramming-languagespass-by-referencenomenclature

Is it OK to call all references variables (and the other way around) in Python?


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?


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.