Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] >>> for x in xs: ... print(x) 1 2 3 4 5 6 7 8 9 0 >>> dir(xs) 0: ['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> it = iter(xs) >>> it 1: <list_iterator object at 0x0000028DA7B992D0> >>> dir(it) 2: ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__length_hint__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__'] >>> next(it) 3: 1 >>> next(it) 4: 2 >>> next(it) 5: 3 >>> next(it) 6: 4 >>> next(it) 7: 5 >>> next(it) 8: 6 >>> next(it) 9: 7 >>> next(it) 10: 8 >>> next(it) 11: 9 >>> next(it) 12: 0 >>> next(it) Traceback (most recent call last): File "<pyshell#16>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> xs 13: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] >>> it = iter(xs) >>> next(it) 14: 1 >>> next(it) 15: 2 >>> next(it) 16: 3 >>> next(it) 17: 4 >>> next(it) 18: 5 >>> for x in it: ... print(x) 6 7 8 9 0 >>> def fn(): ... ... >>> fn 19: <function fn at 0x0000028DA7BD2520> >>> fn() >>> print(fn()) None >>> dir(fn) 20: ['__annotations__', '__builtins__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__getstate__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__type_params__'] >>> def fn(): ... ... ... yield 666 >>> fn 21: <function fn at 0x0000028DA7BD23E0> >>> fn() 22: <generator object fn at 0x0000028DA637D7A0> >>> dir(fn) 23: ['__annotations__', '__builtins__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__getstate__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__type_params__'] >>> dir(fn()) 24: ['__class__', '__class_getitem__', '__del__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__name__', '__ne__', '__new__', '__next__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'close', 'gi_code', 'gi_frame', 'gi_running', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw'] >>> it = fn() >>> it 25: <generator object fn at 0x0000028DA637DB10> >>> next(it) 26: 666 >>> next(it) Traceback (most recent call last): File "<pyshell#38>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> def fn(): ... yield 1 ... yield 2 ... yield 3 >>> it = fn() >>> next(it) 27: 1 >>> next(it) 28: 2 >>> next(it) 29: 3 >>> next(it) Traceback (most recent call last): File "<pyshell#44>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> def fn(): ... print('a') ... yield 1 ... print('b') ... yield 2 ... print('c') ... yield 3 ... print('d') >>> fn 30: <function fn at 0x0000028DA7BD2700> >>> it = fn() >>> next(it) a 31: 1 >>> next(it) b 32: 2 >>> next(it) c 33: 3 >>> next(it) d Traceback (most recent call last): File "<pyshell#51>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> def fn(): ... print('a') ... yield 1 ... print('b') ... yield 2 ... print('c') ... yield 3 ... print('d') ... return None ... print('e') >>> it = fn() >>> next(it) a 34: 1 >>> next(it) b 35: 2 >>> next(it) c 36: 3 >>> next(it) d Traceback (most recent call last): File "<pyshell#57>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> next(it) Traceback (most recent call last): File "<pyshell#58>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> def fn(): ... print('a') ... yield 1 ... print('b') ... yield 2 ... return None ... print('c') ... yield 3 ... print('d') ... yield 4 ... print('e') >>> it = fn() >>> next(it) a 37: 1 >>> next(it) b 38: 2 >>> next(it) Traceback (most recent call last): File "<pyshell#63>", line 1, in <module> next(it) ~~~~^^^^ StopIteration >>> def fn(): ... print('a') ... yield 1 ... print('b') ... yield 2 ... print('c') ... yield 3 ... print('d') ... yield 4 ... print('e') >>> for x in fn(): ... print(x) a 1 b 2 c 3 d 4 e >>>