Python Tip #86 (of 365):

Acknowledge that containment is (sort of) a lie.

Data structures in Python don't contain data...

Well, at least data structures don't contain objects.

Variables don't contain objects: they just point to them.

Likewise, data structures, and all other objects ALSO don't contain objects.

Data structures only POINT to objects.

๐Ÿงต (1/2)

#Python #DailyPythonTip

So a list-of-lists is really a list of references to lists.

The shorthand of thinking of one object as "contained" in another is often helpful, but there is no real "containment" of one object within another in Python.

Most Python gotchas are related to EITHER the pointer nature of variables OR the pointer nature of objects.

So thinking in terms of pointers, for both VARIABLES and OBJECTS will help you avoid most gotchas before the getcha.

๐Ÿงต (2/2)