DragonYu 发表于 2022-7-11 17:48:42

刚刚接触python面向对象的问题

class person:
    def __init__(self,name):
      self.name=name
    @property
    def name(self):
      return self.__name
    @name.setter
    def name(self,value1):
      self.__name=value1
class place:
    def __init__(self,position):
      self.position=position
    @property
    def position(self):
      return self.__position
    @position.setter
    def position(self,value2):
      self.__position=value2
class work:
    def __init__(self,behavior):
      self.__behavior=behavior
    @property
    def behavior(self):
      return self.__behavior
    @behavior.setter
    def behavior(self,value3):
      self.__behavior=value3
    def go_to(self,name,position,behavior):
      print(person.name,'去',place.position,work.behavior)
ly=person('小明')
school=place('学校')
reading=work('读书')
work.go_to(ly,school,reading)


出现错误TypeError: work.go_to() missing 1 required positional argument: 'behavior'   work.go_to三个参数不是已经传入了吗 为什么会出现这种错误 请大神们解答解答

临时号 发表于 2022-7-11 18:05:25

class person:
    def __init__(self,name):
      self.name=name
    @property
    def name(self):
      return self.__name
    @name.setter
    def name(self,value1):
      self.__name=value1
class place:
    def __init__(self,position):
      self.position=position
    @property
    def position(self):
      return self.__position
    @position.setter
    def position(self,value2):
      self.__position=value2
class work:
    def __init__(self,behavior):
      self.__behavior=behavior
    @property
    def behavior(self):
      return self.__behavior
    @behavior.setter
    def behavior(self,value3):
      self.__behavior=value3
    def go_to(self,name,position,behavior):
      print(name.name,'去',position.position,behavior.behavior)
ly=person('小明')
school=place('学校')
reading=work('读书')
reading.go_to(ly,school,reading)
页: [1]
查看完整版本: 刚刚接触python面向对象的问题