python specific
list
__getitem__
s
the[]
syntax for getting item by key or index is just syntax sugar. When you evaluatea[i]
Python callsa.__getitem__(i)
(or
type(a).__getitem__(a, i)
Even if the class ofa
may not explicitly define this method, it is usually inherited from an ancestor class.
https://stackoverflow.com/questions/43627405/understanding-getitem-methodyield, iterable, generators,
yield just create the object once, do not store it in memory.
https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do