What does "Fibonacci" class do in this code?

Can you explain this code for me?

class Fibonacci():
def __init__(self, a, b):
    self.a = a
    self.b = b

def series(self):
    while (True):
        self.a, self.b = self.b, self.a + self.b

f = Fibonacci(0, 1)
for n in f.series():
    if n >= 100: break
    print (r) 

I want to know what does __init__ or self or yield do?

1 answer

  • answered 2017-08-21 14:15 Jan Sila

    you should read a tutorial on classes in Python... the __init__ statement is the constructor of the class, that means it intialises the inner variables. But you can add them at any time or any point - there is no encapsulation in Python