python类学习

Posted 一泽涟漪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()

输出

技术图片
Toyota is a popular automobile brand.
Its headquater is in Japan.
View Code

 

以上是关于python类学习的主要内容,如果未能解决你的问题,请参考以下文章