相关疑难解决方法(0)

为什么一个类的主体在定义时被执行?

与函数相反,类的主体在定义时执行:

class A(object):
    print 'hello'
Run Code Online (Sandbox Code Playgroud)

日期:

hello
Run Code Online (Sandbox Code Playgroud)

为什么会这样?它与@classmethod/ @staticmethodmethods和class属性有关吗?

python class python-2.7 python-internals

16
推荐指数
2
解决办法
2760
查看次数

标签 统计

class ×1

python ×1

python-2.7 ×1

python-internals ×1