0
如果我有對象如何更改對象實例的函數參數的默認值?
>>> 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