1
나는 파이썬에서 oops 개념을 배우고 있고, zed 쇼의 작은 CLI 기반 게임을 개발하는 것은 어려운 방법을 배우지 만 오브젝트의 인스턴스 생성에서는 혼란 스럽다.파이썬에서 클래스의 인스턴스화 사이의 차이
코드 :
class animal(object):
scenes = {
'cat': Cat(),
'dog': Dog(),
'milk': Milk(),
'fight': Fight(),
'timeout': Timeout(),}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
return Map.scenes.get(scene_name)
def opening_scene(self):
return self.next_scene(self.start_scene)
foo = animal('cat')
game = run(foo)
game.play()
누군가가 아래 인스턴스화의 차이점은 무엇입니까 설명 할 수 있습니까?
foo = animal()
및 foo = animal('cat')
지금 내가 foo = animal()
클래스 animal
의 인스턴스에 foo
설정을 이해하고 foo.opening_scene()
foo = animal('cat')
는 무엇을 하는가와 같은 클래스 animal
에서 메서드에 액세스 할 수 있습니까?
'cat'은 ** start_scene ** 매개 변수로 전달됩니다. – Prune