1
私はPythonでoopsの概念を学び、zed shawの小さなCLIベースのゲームを開発するのは難しい方法ですが、オブジェクトのインスタンス化では混乱しました。Pythonでのクラスのインスタンス化の違い
コード:
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
からメソッドにアクセスすることができますか?
パラメータ 'start_scene **'として 'cat'が渡されます。 – Prune