python学习
#python的类中,是个变量,就要套一个 self.变量名 在什么情况下可以不套用self,直接上变量名????import random as r
class Fish:
def __init__(self):
self.x=r.randint(0,10)
self.y=r.randint(0,10)
def mov(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):
#Fish.__init__(self)
super().__init__()
self.hungry=True
def eat(self):
if self.hungry:
print('天天有的吃')
self.hungry=False
else:
print('吃饱了')
发错地方啦{:10_277:}
页:
[1]