Apr-27-2020, 07:29 AM
(This post was last modified: Apr-27-2020, 07:30 AM by astral_travel.)
another quiz,
in the following code:
but then how is it that the class is being wrote with
in the following code:
class MyNumbers: def __iter__(self): self.a = 1 return self def __next__(self): if self.a <= 20: x = self.a self.a += 1 return x else: raise StopIteration myclass = MyNumbers() myiter = iter(myclass) for x in myiter: print(x)i see that in line 14 -
myclass = Mynumbers()
- as i understand it - myclass
is a new variable ? which is assigned the value of the class MyNumbers
?but then how is it that the class is being wrote with
()
- (that's a function feature, isn't it ?)