2

I am learning Python now, so having very petty doubts, sometimes stupid even. So if find something resembling to one of the either, please ignore!

The print() in python prints onto the standard output. So basically, if I write

print('Hello World')

I get to see Hello World on the in the output. But what happens when I have multiple print() nested within each other? Something like this..

print(print("Hello World"))

Output is:

    Hello World
    None

Similarly, if I have:

print(print(print()))

Then the output is:

   //blank line
   None
   None

I am unable to understand what is happening here, please if anyone could explain, that would be a great help.

Thank you!

1 Answer 1

6

The print() function returns None (like most functions that are called for their side effects). The outer print() is just printing that return value.

There's no particularly good use case for ever nesting print functions like that.

Sign up to request clarification or add additional context in comments.

3 Comments

@Wobble Ok, but the print() returns a string in the first case "Hello World", then how come it even prints None after that?
It doesn't return a string. It prints a string to the standard output.
It prints None because the inner print() returns None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.