<p>一般来说,我对python和编程还不熟悉,所以非常感谢您对这一点的任何澄清。在</p>
<p>例如,在以下代码中:</p>
<pre><code> #Using a class
class Monster(object):
def __init__(self, level, damage, duration):
print self
self.level = level
self.damage = damage
self.duration = duration
def fight(self):
print self
print "The monster's level is ", self.level
print "The monster's damage is ", self.damage
print "The attack duration is ", self.duration
def sleep(self):
print "The monster is tired and decides to rest."
x = Monster(1, 2, 3)
y = Monster(2, 3, 4)
x.fight()
y.fight()
y.sleep()
#just using a function
def fight_func(level, damage, duration):
print "The monster's level is ", level
print "The monster's damage is ", damage
print "The attack duration is ", duration
fight_func(1, 2, 3)
fight_func(5,3,4)
</code></pre>
<p>纯函数版本看起来更干净,并给出相同的结果。在</p>
<p>你可以在一个对象上创建和调用许多方法的类的主要值,例如fight或sleep?在</p>