class Date(object):
def __init__(self, day=0, month=0, year=0):
self.day = day
self.month = month
self.year = year
def __repr__(self) -> str:
return f"Date({self.day}, {self.month}, {self.year})"
@classmethod
def from_string(cls, date_as_string):
day, month, year = map(int, date_as_string.split('-'))
date1 = cls(day, month, year)
return date1
@classmethod
def millenium(cls, month, day):
return cls(month, day, 2000)
@staticmethod
def is_date_valid(date_as_string):
day, month, year = map(int, date_as_string.split('-'))
return day <= 31 and month <= 12 and year <= 399933 Class vs Instance Method
From: This stackoverflow
date1 = Date.from_string('11-09-2012')
date1Date(11, 9, 2012)
date2 = Date.is_date_valid('11-09-2012')
date2True