您的位置:首页 > 编程语言 > Python开发

Python:类的继承关系

2017-08-13 19:23 423 查看
import random as r
class Fish:
def __init__(self):
self.x=r.randint(0,10)
self.y=r.randint(0,10)
def move(self):
self.x-=1
print('我的位置是:',self.x,self.y)

class Goldfish(Fish):
pass
class Carp(Fish):
pass
class Salmon(Fish):
pass
class Shark(Fish):
def __init__(self):
self.hungry=True
    def eat(self):
if self.hungry:
print("吃货的梦想就是天天有的吃…………")
self.hungry=False
        else:
print("太累了,吃不下了")

fish=Fish()
print(fish.move())
print(fish.move())

goldfish=Goldfish()
print(goldfish.move())
print(goldfish.move())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: