1. class DataTest(object):
    2. day = 0
    3. month = 0
    4. year = 0
    5. def __init__(self, year=0, month=0, day=0):
    6. self.day = day
    7. self.month = month
    8. self.year = year
    9. def out_date(self):
    10. print("year :", self.year)
    11. print("month :", self.month)
    12. print("day :", self.day)
    13. @classmethod
    14. def get_data(cls, string_date):
    15. """处理'2018-8-18'字符格式"""
    16. year, month, day = map(int, string_date.split('-'))
    17. return cls(year, month, day)