![](/img/trans.png)
[英]Why is the print statement in the class executed when an object isn't even created?
[英]Print statement in class getting executed even though there is no class instance/object
我的python文件的内容
class myclass(object):
def __init__(self):
pass
def myfun(self):
pass
print ("hello world")
执行文件输出
hello world
询问
since I did not create object of class . How's it still able to print "hello world"
它会接到一个电话,因为python就是这样。 您的代码将始终返回输出。
你好,世界
class myclass(object):
def __init__(self):
pass
def myfun(self):
print("hello world")
pass
如果要避免这种情况,则必须在方法内部添加print语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.