當前位置:成語大全網 - 新華字典 - Python中靜態方法可以訪問類定義的字典麽

Python中靜態方法可以訪問類定義的字典麽

class MyClass:

class_dict = {}

def __init__(self):

self.value2 = 2

@staticmethod

def static():

static_dict = {}

print(static_dict)

print(self.class_dict) #此處無法執行 NameError: name 'self.class_dict' is not defined

#很遺憾,不可以

sc = MyClass()

sc.static()