Say we have run this line of code in an Python or IDLE shell:
print("hai")
The below appears on screen:
hai
This just seems counterintuitive to me, since print(arg) is a void function and thus returns None when evaluated, always; NoneType is a datatype in python, yet it is not displayed on the window when an expression evaluates to it, while integers are:
5
makes this appear on screen (running on shell):
5
Is this non-displaying behaviour hard-coded into python to only be a feature of NoneType data?
I’m asking this question because there seems to be ambiguity in what is considered an “output,” and I’m worried this ambiguity is going to make my mid-terms pretty disastrous. For example, consider this line of code…
…run in shell:
5
makes this appear on screen:
5
…compiled and run:
5
Doesn't make anything appear on screen.
--
The expression 5 trivially evaluates to the integer 5 in Python, but is the integer 5 an output in the same way that...
print(5)
…outputs “5” on the screen? And how about the NoneType data object that the print(5) function call evaluates to; would that be an output too?
I guess the practical ramifications of my question would be this; say someone asks you this question:
What is the output of this line of code?:
print(5)
Would the correct answer be:
(a).
5
None
(b).
5
or
(c).
None ?
and for good measure, how about this question:
What is the output of this line of code?:
5
Would the correct answer be:
(a).
or
(b).
5
The answer to the two above questions depends on a couple things:
“What exactly constitutes an output? Is an evaluated value an output? Or are outputs literally just: what would the screen look like after I press the return key”
“Does how are we running the code matter? Since writing the line of code in TextEdit, compiling it, and then running it yields different things appearing on the screen than typing the line of code in the shell and hitting return."