Artificial intelligent assistant

Pythonの特殊メソッド iter ではクラスのオブジェクトも引数として取る事が可能? Python `iter` Python > > class ITER(): > def __init__(self, max = 0): > self.max = max > > def __iter__(self): > self.n = 0 > return self > > def __next__(self): > if self.n <= self.max: > result = 2 ** self.n > self.n += 1 > return result > else: > raise StopIteration > > x = ITER(2) > i = iter(x) > print(next(i)) > print(next(i)) > print(next(i)) > `iter()`

Pythoniterable `iter()`() iterable

iterableiterable

iterable

> An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict, file objects, and objects of any classes you define with an `__iter__()` method or with a `__getitem__()` method that implements Sequence semantics.



* `__iter__()`. (iterator .)





* `__getitem__()`Sequence .



iterable

`ITER`1`__iter__()`. (itertor .)iterable`iter()`

* * *

iterablefor-in


# `ITER`
x = ITER(2)
for i in x:
print(i)

a, b, c = x
print(a, b, c)

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e6cc2a6419073b64bd415ee35f5dd5cc