私は udacity.com からこの例を見ました:
def say_hi():
return 'hi!'
i = 789
class MyClass(object):
i = 5
def prepare(self):
i = 10
self.i = 123
print i
def say_hi(self):
return 'Hi there!'
def say_something(self):
print say_hi()
def say_something_else(self):
print self.say_hi()
出力:
>>> print say_hi()
hi!
>>> print i
789
>>> a = MyClass()
>>> a.say_something()
hi!
>>> a.say_something_else()
Hi there!
>>> print a.i
5
>>> a.prepare()
10
>>> print i
789
>>> print a.i
123
a.say_something()
equalshi!
と notの理由を除いて、すべてを理解していHi there!
ます。say_something()
その後に呼び出すと、クラス内にあるものを呼び出すので、それは私にとって奇妙ですsay_hi()
。私は何か重要なことを逃したと思います..