mercredi 13 juillet 2016

what gets returned when you return self?


what gets returned when you return 'self' inside a python class? where do we exactly use return 'self'? In the below example what does self exactly returns

class Fib:
'''iterator that yields numbers in the Fibonacci sequence'''

def __init__(self, max):
    self.max = max

def __iter__(self):
    self.a = 0
    self.b = 1
    return self

def __next__(self):
    fib = self.a
    if fib > self.max:
        raise StopIteration
    self.a, self.b = self.b, self.a + self.b
    print(self.a,self.b,self.c)
    return fib

Aucun commentaire:

Enregistrer un commentaire