#2.1 __init__ (06:27) - airbnb-clone-backend

star_is_mine·2022년 11월 4일
0

배운점

python 에서 Class 를 초기화하고 사용하는 법을 배웠습니다.
아래 코드의 내용을 이미 알고 있다면 이번 강의는 스킵 해도 무방합니다.

class Player:

  def __init__(self, name, xp=0):  
  	# 여기서 self 는 class Player 가 만들어낸 instance 를 가리킵니다.
    self.name = name
    self.xp = xp
  
  # say_hello 메서드 정의
  def say_hello(self):
    print(f"i'm {self.name} hi hello")


mike = Player("mike", 5)

print(mike.name)
print(mike.xp)
print(mike.say_hello())
  • 나중에 Player 클래스를 상속받은 다른 클래스는 부모클래스인 Player 클래스에 정의된 say_hello 메서드를 사용하고 싶은 경우 super 를 사용해야 합니다. 이해 못한 경우 반드시 찾아보세요.

핵심명령어 정리

None

None

profile
i have a dream and I will make my dreams come true.

0개의 댓글