<pre name="code" class="python">#coding:utf8
import turtle
class Things:#定义“东西”类
pass
class Inanimate(Things):#定义”非活动事物“类
pass
class Animate(Things):#定义“活动事物”类
pass
class Slidewalks(Inanimate):#定义”人行道“类
pass
class Animals(Animate):#定义”动物“类
def breathe(self):
print "breathing"
def move(self):
print "moving"
def eat_food(self):
print "eating food"
class Mammals(Animals):#定义”哺乳动物“类
def feed_young_with_milk(self):
print "feeding young"
class Giraffes(Mammals):#定义”长颈鹿“类
def __init__(self,spots):
self.giraffe_spots=spots
def find_food(self):
self.move()
print "I've found food!"
self.eat_food()
def eat_leaves_from_tree(self):
print "eating leaves"
def dance_a_jig(self):
self.move()
self.move()
self.move()
self.move()
ozwald=Giraffes(100)
gertrude=Giraffes(150)
print ozwald.giraffe_spots
print gertrude.giraffe_spots
'''
avery=turtle.Pen()
kate=turtle.Pen()
avery.forward(50)
avery.right(90)
avery.forward(20)
kate.left(90)
kate.forward(100)
jacob=turtle.Pen()
jacob.left(180)
jacob.forward(80)
'''
msg=raw_input("Please press Enter key over!")
趣味导学Python——类与对象(一)
最新推荐文章于 2021-03-13 16:14:29 发布