-1

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.

1 Answer 1

2

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
3
  • Why is this marked as the answer? It doesnt even compile :S
    – AlanK
    Commented Feb 17, 2019 at 13:17
  • i have posted it again below please go through the code Commented Feb 20, 2019 at 5:45
  • Delete your other answer -- I've updated this one (since its marked as the answer)
    – AlanK
    Commented Feb 20, 2019 at 9:30

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.