Python: Making objects callable

Problem Statement Have you ever wandered if we could make an object callable? Yes, I mean just use the object name as if you were calling function! Intersted? Solution [sourcecode language="python"] class Add: def __init__(self, num1, num2): self.num1 = num1 self.num2 = num2 print "Sum of", self.num1,"and",self.num2, "is:" def __call__(self): return (self.num1 + self.num2) add … Continue reading Python: Making objects callable