Hi fellow codecademy learners,
print(print(1)) returns 1 and None. Please help me on why None and 1 are being returned. To me, either one should be returned, not both.
Thank you in advance!!
Hi fellow codecademy learners,
print(print(1)) returns 1 and None. Please help me on why None and 1 are being returned. To me, either one should be returned, not both.
Thank you in advance!!
why not both?
None is the absence of the return value, so the inner print doesn’t return any value, thus the outer print function call “prints” None
Thank you so much for your help!!! but I’m still confused. if the inner print doesn’t return any value, where did 1 come from?
print() is a function call, the argument (
1) in this case is printed, but the function itself doesn’t return anything, it only print the argument(s)
Thank you so much! stetim94!!! I feel like I get it now! So, the inner print returns 1, and since the inner print which is a function doesn’t return anything, the outer print returns None. In conclusion, the inner print returns 1 and the outer print return None!! Thanks!
using
return here is an unfortunate choice of words.
print() prints its argument.
Return literally means handing back, so for example:
def example(): return "hello world"
the example function returns a string
doing
print(1) will print 1 (its argument), given the print function doesn’t have a
return keyword in its body, we get None (the absence of a return value)
print vs return is now much clearer thanks to you, stemtim94! I wrote and played with simple functions using return and print just like in your example. I feel more confident about how they work. Its amazing that even the simplest thing still offers you to have an opportunity to go deeper.
Thanks again!
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.