源代码如下:
class Turtle: def __init__(self, x): self.num = x class Fish: def __init__(self, x): self.num = x class Pool: def __init__(self, x, y): self.turtle = Turtle(x) self.fish = Fish(y) def print_num(self): print('水池里总共有%d只乌龟,%d只鱼'%(self.turtle.num, self.fish.num)) pool = Pool(1, 10) pool.print_num()
运行结果如下:
水池里总共有1只乌龟,10只鱼
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)