趣味导学Python——类与对象(一)

<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!")



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值