类是有一些系列有共同特征或行为事物的抽象概念的综合
使用class来定义一个类(如果使用def定义函数)
class CocaCola():
it_taste = 'so good!'
coke_for_bum = CocaCola()#等号左边为实例(类似变量),右边是类的名称,这种行为称为类的实例化,
coke_for_president = CocaCola()
print(coke_for_bum.it_taste)
print(coke_for_president.it_taste)
class CocaCola():
formula = ['caffeine','sugar','water','soda']#等号左边为类的属性
coke_for_me = CocaCola()
coke_for_you = CocaCola()
print(CocaCola.formula)
print(coke_for_me.formula)
print(coke_for_you.formula)
for element in coke_for_you.formula:
print(element)
coke_for_China = CocaCola()
coke_for_China.local_logo = '可口可乐'#通过object.new_atrr进行赋值,得到一个新的实例属性(变量)
print(coke_for_China.local_logo)
实例属性和类属性的区别: