1.

Write a class with two private class variables and print the sum using a method (python)

Answer»

A function PERFORMS an action using some set of input parameters. Not all functions are APPLICABLE to all kinds of data. Classes are a way of GROUPING together related data and functions which ACT upon that data.A class is a kind of data type, just like a string, integer or list. When we create an object of that data type, we call it an INSTANCE of a class.def age(self): if hasattr(self, "_age"): return self._age today = datetime.date.today() age = today.year - self.birthdate.year if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day): age -= 1 self._age = age return age



Discussion

No Comment Found