[英]Print statement inside functioncall is not printing values Python
When there is a print statement inside a function, it is not printing. 当函数内部有打印语句时,则不打印。 I dont understand what is going wrong.
我不明白怎么了。
def test():
print("please print this")
return "return this"
And, my main function is like this: 而且,我的主要功能是这样的:
if __name__ == "__main__":
classwhereiwrotefunction.test()
When I use a debugger, and try to store the return value in a variable, it does show the value. 当我使用调试器并尝试将返回值存储在变量中时,它会显示该值。 But, does not print it.
但是,不打印它。
the problem is with indentation I guess. 我猜问题在于缩进。 Try the below code it will work.
试试下面的代码,它将起作用。
class Class_name:
def test(self):
print("please print this")
return "return this"
if __name__ == "__main__":
class_name = Class_name()
print(class_name.test())
>> please print this
>> return this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.