#### Solution to exercise 9.1 in the book # class Line is from section 9.1.1 in the book class Line(object): def __init__(self, c0, c1): self.c0 = c0 self.c1 = c1 def __call__(self, x): return self.c0 + self.c1 * x def table(self, L, R, n): """Return a table with n points for L <= x <= R.""" s = "" import numpy as np for x in np.linspace(L, R, n): y = self(x) s += "%12g %12g\n" % (x,y) return s # The class below is from exercise 9.1 in the book class Parabola0(Line): pass # We create an instance of class Parabola0 p = Parabola0(0, 1) # What is inside p? print(dir(p)) # We see that the instance contains many special variables # and methods of the form __NAME__ and also c0, c1, table. # These are exactly the same attributes that we would find # in an instance of class Line (as you can verify yourself # by creating an instance q of class Line and perform dir(q)). # The instance variables c0 and c1 and their values can # also be seen by looking at the __dict__ variable: print(p.__dict__)