【发布时间】:2015-08-14 15:36:30
【问题描述】:
如果我有对象
>>> class example_class():
>>> def example_function(number, text = 'I print this: '):
>>> print text, number
我可以更改 example_function 输入参数
>>> example_instance = example_class()
>>> print example_instace.example_function(3, text = 'I print that: ')
现在我希望每次使用example_instace 时都使用I print that:。是否可以更改text 的默认值,以便我得到这种行为:
>>> example_instace = example_class()
>>> print example_instance.example_function(3)
I print this: 3
>>> default_value(example_instance.text, 'I print that: ')
>>> print example_instance.example_function(3)
I print that: 3
【问题讨论】:
标签: python python-2.7 class