__getitem__ and __iter__ Implement Iteration : getitem « Class « Python Tutorial






class stepper: 
     def __getitem__(self, i): 
        return self.data[i] 

X = stepper(  )                       
X.data = "Spam" 

print X[1]                          
for item in X:                      
     print item,                    


print 'p' in X                      

print [c for c in X]                

print map(None, X)                  

(a, b, c, d) = X                    
print a, c, d 

print list(X), tuple(X), ''.join(X) 

print X








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