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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.