KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Why does defining __getitem__ on a class make it iterable? For instance if I write: class B: def __getitem__(self, k): return k cb = B() for k in cb: print k I get the output: 0 1 2 3 4 5 ... I would really expect to see an error returned from for k in cb: .
Tags (comma-separated)
Save Edits
Cancel