user1161545
user1161545

Reputation:

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?

Upvotes: 0

Views: 84

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123470

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.

Upvotes: 2

Related Questions