""" Ex 7.11 from A Primer on... """ from math import * class F: def __init__(self,a,w): self.a = a self.w = w def __call__(self,x): return exp(-self.a*x)*sin(self.w*x) def __str__(self): return 'exp(-a*x)*sin(w*x)' """ Simple demonstration that the __call__ and __str__ methods work: """ f = F(a=1.0, w=0.1) print(f(pi)) print(f) """ Terminal> python F2.py 0.01335383513703555 exp(-a*x)*sin(w*x) """