Reputation: 523
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!
Upvotes: 2
Views: 2169
Reputation: 90007
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.
Upvotes: 6