What the Pythons docs means by "container" ?

candide pascal.ortiz at gmail.com
Tue Feb 17 21:14:44 EST 2015


Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit :

> 
> So, what's a container? It's a thing that you put other objects into.

I agree with this approach. The important point to consider here is the last word in your definition : "into". There is the container and there is the content (the objects into). The so-called built-in containers (list, string, etc) are in conformance with this view. Now, regarding a range object as a container disagrees completely with the definition given in the PLR : there is no contents and hence there is no container. For instance, range(10**6) doesn't hold any kind of object, there are no reference to the int objects 0, 1, 2, ... As the range's docstring explains, range returns a VIRTUAL sequence.



More information about the Python-list mailing list