python类学习

创建关于汽车的类

class Cars():

    def __init__(self, brand, country):
        self.brand = brand
        self.country = country

    def show_brand(self):
        print(self.brand.title() + " is a popular automobile brand.")

    def show_country(self):
        print("Its headquater is in " + self.country.title() + ".")


my_car = Cars('toyota', 'Japan')
my_car.show_brand()
my_car.show_country()

输出

python类学习
Toyota is a popular automobile brand.
Its headquater is in Japan.
View Code

 

上一篇:如何将云原生工作负载映射到 Kubernetes 中的控制器


下一篇:第二课:3-8译码器