码迷,mamicode.com
首页 > 编程语言 > 详细

python类学习

时间:2019-12-22 00:57:05      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:ini   opened   mobile   japan   python类   color   elf   yota   汽车   

创建关于汽车的类

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类学习

标签:ini   opened   mobile   japan   python类   color   elf   yota   汽车   

原文地址:https://www.cnblogs.com/ilifeilong/p/12078588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!