# instance attribute (필수) def__init__(self, name, age): self.name = name self.age = age
if __name__ == "__main__": kim = Person("Kim", 30) lee = Person("Lee", 28) # access class attribute print("Kim은 {}".format(kim.__class__.country)) print("Lee는 {}".format(lee.__class__.country))
classPerson: """ 사람을 표현하는 클래스 *** Attributes ---------- name: str Name of the person age: int Age of the person Methods ------- info(additional=""): Prints the person's name and age """
def__init__(self, name, age): """ Constructs all the neccessary attributes for the person object Parameters ---------- name: str Name of the person age: int Age of the person """
self.name = name self.age = age definfo(self, additional=None): """ Prints the person's information Parameters ---------- additional: str, optional more info to be diplayed (Default is None) / A, B, C Returns ------- None """ print(f'My name is {self.name}. I am {self.age} years old. ' + additional)
if __name__=="__main__": print(Person.__doc__) person = Person("Jiwon", age = 27) person.info("I wanna be a data analyst.")
사람을 표현하는 클래스
***
Attributes
----------
name: str
Name of the person
age: int
Age of the person
Methods
-------
info(additional=""):
Prints the person's name and age
My name is Jiwon. I am 27 years old. I wanna be a data analyst.