__getitem__ Intercepts Index References : getitem « Class « Python Tutorial






class indexer: 
    def __getitem__(self, index): 
        return index ** 2 

X = indexer(  ) 
X[2]                                
for i in range(5): 
    print X[i],








11.19.getitem
11.19.1.__getitem__ used in a for loop
11.19.2.__getitem__ and __iter__ Implement Iteration
11.19.3.__getitem__ Intercepts Index References