+28

# Could someone explain why does it print Hello None None None?

print(print(print(print("Hello"))))

4/19/2019 8:04:22 PM

Soheil Elahi

+17

Tahir Usman due to the evaluation order It must evaluate the innermost execution before moving on to the next one Take this code for instace def foo(x): return x + 1 def bar(x): return x * 2 print(bar(foo(20))) As you can see, the "bar" function takes the return value of "foo" so it has to be evaluated first "foo" takes the value 20 and return 21 which is then passed to the "bar" function which in turn returns 42 which is outputted by "print"

+24

Soheil Elahi inner most print, prints "Hello" and returns None. Then the argument to next print is None, so it prints None and returns None and it carrries on, Try this x = print("Hello") print(x) // prints None Any function in python that does not explicitly returns a value, implicitly return None.

+17

~ swim ~ Great answer, thanks.

+17

Burey, thanks.👌👌👌

+15

So why does it print None too?

+15

Burey It was a great example.👍👍👍

+14

The print function does not have a return value So going thru the evaluation order the inner most print call print("Hello") is executed and outputs "Hello" Each other print call will output the value which retuned from the call of print which is None you can test yourself to see what a function with no return value prints def foo(): x = 42 # doesn't matter what the function does, as long as it doesn't return anything print(foo()) output: None

+13

Tahir, it starts from the innermost one.

+12

Yes same doubt here can any one explain it

+6

Burey bro, why it doesn't print none none none hello?

+5

Just print() function returns None

+4

Soheil Elahi 🤘

+3

Print expects a string, which is only true for the innermost one?

+3

Muhammad Reshma i've explained it here See my previous answer to this post

+2

"print( )" is actually a function, and it prints the statements inside the paratheneses, known as arguments. The innermost print prints "Hello". But the next print does not have any string argument, and the value is absent. Absence of a value in python 3 is declared by "None". As the other prints don't have string arguments, they print None.

0

Salut

0

0

Mnv

0

Print ("hello to the world") RUN hello to the world