class indexer: def __getitem__(self, index): return index ** 2 X = indexer() print X[2] # X[i] calls __getitem__(X, i) for i in range(5): print X[i],