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):
= map(int, date_as_string.split('-'))
day, month, year = cls(day, month, year)
date1 return date1
@classmethod
def millenium(cls, month, day):
return cls(month, day, 2000)
@staticmethod
def is_date_valid(date_as_string):
= map(int, date_as_string.split('-'))
day, month, year return day <= 31 and month <= 12 and year <= 3999
23 Class vs Instance Method
From: This stackoverflow
= Date.from_string('11-09-2012')
date1 date1
Date(11, 9, 2012)
= Date.is_date_valid('11-09-2012')
date2 date2
True