Python 日期类设计:无参数和多参数构造方法示例
class Date: def init(self, year=2021, month=1, day=1): self.year = year self.month = month self.day = day
def __str__(self):
return f'{self.year}-{self.month}-{self.day}'
无参数构造方法
date1 = Date() print(date1)
三个参数构造方法
date2 = Date(2022, 11, 9) print(date2)
原文地址: https://www.cveoy.top/t/topic/nXSZ 著作权归作者所有。请勿转载和采集!