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.
相关推荐
zhuquan0 2020-05-25
class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =
lhxxhl 2020-05-16
PHP学习笔记 2020-05-07
DCXabc 2020-05-01
bcbeer 2020-05-02
fly00love 2020-03-08
liusarazhang 2020-03-06
zhuxianfeng 2020-03-03
Kwong 2020-03-01
ladysosoli 2020-03-01
liugan 2020-02-25
Dimples 2020-02-14
wangqing 2020-02-13
fanhuasijin 2020-02-03