如何更改对象实例的函数参数的默认值?

时间:2015-08-14 15:36:31

标签: python python-2.7 class

如果我有对象

>>> 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: ')

现在,我希望每次使用I print that:时始终使用example_instace。是否可以更改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

0 个答案:

没有答案