python类学习

huakai 2019-12-22

创建关于汽车的类

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()

输出

Toyota is a popular automobile brand.
Its headquater is in Japan.

相关推荐