class MyRange:
def __init__(self, stop):
self.__stop = stop
def __iter__(self):
number = 0
while number < self.__stop:
yield number
number += 1
for i in MyRange(3):
print(i)
class Skill:
def __init__(self, a):
self.a = a
class SkillManager:
def __init__(self):
self.__list = []
def add_skill(self, skill):
self.__list.append(skill)
def __iter__(self):
for item in self.__list:
yield item
manager = SkillManager()
manager.add_skill(Skill(2))
manager.add_skill(Skill(3))
manager.add_skill(Skill(4))
for item in manager:
print(item.a)
def my_range(stop_value):
for i in range(stop_value):
yield i
for item in my_range(2):
print(item)
|