7.6 更多参数

    和函数一样,类的方法也能有属于自己的参数,我们先来试着在 .drink() 方法上做些改动:

    class CocaCola:
    formula = ['caffeine','sugar','water','soda']
    def drink(self,how_much):

    if how_much == 'a sip':
    print('Cool~')
    elif how_much == 'whole bottle':
    print('Headache!')

    ice_coke = CocaCola()
    ice_coke.drink('a sip')

    运行结果:

    >>> Cool~