Class (3)

Grace Goh·2022년 9월 25일
0

Python

목록 보기
24/24
class Dog:
    vaccine = 'covid19'

    def __init__(self, dogname, dogage):
        self.name = dogname
        self.age = dogage
    
    def info(self):
        return '{} is {} years old.'.format(self.name, self.age)
    
    def speak(self, sound):
        return '{} says {}!'.format(self.name, sound)
        
# 인스턴스 생성
dog1 = Dog('Happy', 10)
dog2 = Dog('Rafael', 37)
dog3 = Dog('Sunflower', 35)

# method 호출
print(dog1.info())
print(dog1.speak("I'm happy"))
print(dog2.speak("I am Rafael"))
# Happy is 10 years old.
# Happy says I'm happy!
# Rafael says I am Rafael!
profile
Español, Inglés, Coreano y Python

0개의 댓글