import numpy as np
class Line:
"""Class for lines"""
def __init__(self, c0, c1):
self.c0, self.c1 = c0, 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 = ''
for x in np.linspace(L, R, n):
y = self(x)
s += f'{x:12g} {y:12g}\n'
return s
class Parabola0(Line):
"""Class for parabola"""
pass
l1 = Line(1,1)
p1 = Parabola0(1,1)
print(isinstance(p1,Parabola0))
print(isinstance(p1,Line))
print(dir(p1))
print(p1.__dict__)
print(p1.__doc__)
"""
Terminal> python dir_subclass.py
True
True
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'c0', 'c1', 'table']
{'c0': 1, 'c1': 1}
Class for parabola
"""