Object lifetime in Python

Wikipedia says, " In computer science, the object lifetime (or life cycle) of an object in object-oriented programming is the time between an object's creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed. " Typically, an object goes through the following phases during it's lifetime: … Continue reading Object lifetime in Python

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