diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/getitem.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/basics/getitem.py b/tests/basics/getitem.py new file mode 100644 index 0000000000..f39296aca3 --- /dev/null +++ b/tests/basics/getitem.py @@ -0,0 +1,22 @@ +# create a class that has a __getitem__ method +class A: + def __getitem__(self, index): + print('getitem', index) + if index > 10: + raise StopIteration + +# test __getitem__ +A()[0] +A()[1] + +# iterate using a for loop +for i in A(): + pass + +# iterate manually +it = iter(A()) +try: + while True: + next(it) +except StopIteration: + pass |