class in python

# # -*- coding:UTF-8 -*-
class Turtle:
    def __init__(self,x):
        self.num = x

class Fish:
    def __init__(self,y):
        self.num = y

class Pool():
    def __init__(self,x,y):
        self.turtle = Turtle(x)
        self.fish = Fish(y)
    def print_num(self):
        print("池塘里一共有%d只鱼,%d只乌龟" % (self.fish.num,self.turtle.num))

pool = Pool(5,10)
pool.print_num()

class in python_第1张图片

你可能感兴趣的:(python)