我想在方法中定义一个属性:
\n\nclass variables:\n def definition(self):\n self.word = "apple"\nRun Code Online (Sandbox Code Playgroud)\n\n然后我想使用定义的属性:
\n\ntest = variables()\nprint test.definition.word\nRun Code Online (Sandbox Code Playgroud)\n\n我没有写,而是\'apple\'收到错误:
Traceback (most recent call last):\n File "bezejmenn\xc3\xbd.py", line 6, in <module>\n print test.definition.word\nAttributeError: \'function\' object has no attribute \'word\'\nRun Code Online (Sandbox Code Playgroud)\n