出于某种原因,当我围绕财产功能的争论而转变时,它就留下了一个错误。 我只想理解为什么。
class Geeks:
def __init__(self):
self._age = 0
# function to get value of _age
def get_age(self):
print("getter method called")
return self._age
# function to set value of _age
def set_age(self, a):
print("setter method called")
self._age = a
age = property(get_age, set_age)
mark = Geeks()
mark.age = 10
print(mark.age)
产出:
setter method called
getter method called
10
错误发生时,我转接了<代码> = 财产(植被、定型_age)
class Geeks:
def __init__(self):
self._age = 0
# function to get value of _age
def get_age(self):
print("getter method called")
return self._age
# function to set value of _age
def set_age(self, a):
print("setter method called")
self._age = a
age = property(set_age, get_age)
mark = Geeks()
mark.age = 10
print(mark.age)
产出
ERROR!
Traceback (most recent call last):
File "<string>", line 18, in <module>
TypeError: Geeks.get_age() takes 1 positional argument but 2 were given
Why am I not allowed to switch around the arguments?