from datetime import date
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
@classmethod
def fromBirthYear(cls, name, birthYear):
return cls(name, date.today().year - birthYear)
# Person(name, age올해-출생연도)
def display(self):
print(self.name + "'s age is: " + str(self.age))
me = Person('Grace', 35)
me.display()
# 인스턴스.method
# 인스턴스 = class.method
you = Person.fromBirthYear('Rafa', 1986)
you.display()
Grace's age is: 35
Rafa's age is: 36