我正在经历“Learning Python The Hard Way”,然后我开始上课了。我理解它(或者我至少认为我理解了!)并尝试使用我自己的名字、函数等创建一个简单的变体......
现在我遇到的问题是代码不会在命令行\powershell 中返回任何内容。它没有任何错误,它只是转到另一行输入。
这是代码:
class Animal(object):
'''represents any animal'''
def __init__(self, legs, size):
self.legs = legs
self.size = size
def detail_animal(self):
'''show # of legs and size'''
print "Name: %r\nAge: %r" % (self.legs, self.size)
class canine(Animal):
'''represents a canine'''
def __init__(self, legs, size, hair_length):
Animal.__init__(self, legs, size)
self.hair_length = hair_length
def detail_canine(self):
Animal.detail(self)
print 'Has %r inch long hairs.' % self.hair_length
class feral_cat(Animal):
'''represents a feral cat'''
def __init__(self, legs, size, tail_length):
Animal.__init__(self, legs, size)
self.tail_length = tail_length
def detail_feral(self):
Animal.detail(self)
print "Tail Length: %r" % tail_length
c1 = canine(4, 2, 0.5)
c2 = canine(5, 3, 0.75)
fc1 = feral_cat(4, 5, 3)
a = Animal(4, 2)
提前致谢!