【发布时间】:2023-02-15 22:46:24
【问题描述】:
我想访问 init 中的类变量
class Hare:
APP = 10;
def __init__(self):
print(APP)
h = Hare()
它给出错误
!!! NameError: name 'APP' is not defined
【问题讨论】:
-
您是要使用
self.APP = 10和print(self.APP)吗?另外,分号是技术上在 Python 中有效,但您可以将其省略。 -
self.APP或Hare.APP
标签: python