Test iteration.

This commit is contained in:
Captain ALM 2022-11-30 19:52:29 +00:00
parent e699ebf017
commit 8fc8c48ff3
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

51
main.py
View File

@ -1,31 +1,24 @@
#Train Class Example #Iteration test
class Train: a = (1, 2, 3)
def __init__(self, class_, name): b = iter(a)
self.class_ = class_ print(next(b))
self.name = name print(next(b))
self.name = name if name else "#" print(next(b))
def __str__(self):
return f"Class {self.class_}({self.name})"
def manufacturer(self):
return ""
class BREL(Train): class A:
def __init__(self, class_):
super().__init__(class_, "")
def manufacturer(self):
return "BREL"
class PEP(Train):
def __init__(self, class_):
super().__init__(class_, "PEP")
def manufacturer(self):
return "Unknown"
#The presendence of definitions is the order in the inheritance bracket
class C315(BREL, PEP):
def __init__(self): def __init__(self):
super(BREL,self).__init__(315) self.n = 0
def __init__(self, n):
c315 = C315() self.n = n
print(c315, c315.manufacturer()) def __iter__(self):
del c315 self.i = 0
return self
def __next__(self):
if self.i > 100 or self.i < -100: raise StopIteration
z = self.i
self.i -= self.n
return z
c = A(2)
d = iter(c)
for x in d:
print(x)