New course! Every coder should learn Generative AI!
Try a free lesson+ 18
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"
+ 30
Yes same doubt here can any one explain it
+ 15
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
+ 7
Just print() function returns None
+ 7
Muhammad Reshma i've explained it here
See my previous answer to this post
+ 6
Burey bro, why it doesn't print none none none hello?
+ 5
+ 3
Print expects a string, which is only true for the innermost one?
+ 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
F
0
Mnv
0
Print ("hello to the world")
RUN
hello to the world