Код IT Загрузка примера кода…

Python main.py
class CountDown:
    def __init__(self, start):
        self.current = start

    def __iter__(self):
        return self

    def __next__(self):
        if self.current < 0:
            raise StopIteration
        value = self.current
        self.current -= 1
        return value

# Использование
for n in CountDown(3):
    print(n)  # 3, 2, 1, 0
class CountDown:
    def __init__(self, start):
        self.current = start

    def __iter__(self):
        return self

    def __next__(self):
        if self.current < 0:
            raise StopIteration
        value = self.current
        self.current -= 1
        return value

# Использование
for n in CountDown(3):
    print(n)  # 3, 2, 1, 0