When I execute:
Print[x]//InputForm
I get a Null
at the last line of the result.
This is an example shown in the documentation of Print
command in the Mathematica's official web page.
What is the Null
? Why does it appear?
When I execute:
Print[x]//InputForm
I get a Null
at the last line of the result.
This is an example shown in the documentation of Print
command in the Mathematica's official web page.
What is the Null
? Why does it appear?
Mathematica is a term rewriting system. It works by taking an input expression and transforming it according to some rules to produce an output expression. The implication is that every evaluation will have a result. For every input there is an output.
Null
is simply the expression used to represent "no result". In StandardForm and OutputForm it is not printed. Thus when the result is Null
, it is usually simply not shown. Try evaluating Null
alone and it will appear that there is no output. In InputForm however it is shown as "Null
". You can also try InputForm[Null]
.
Clarification: When you evaluate Print[x] // InputForm
, Null
is not "the last line of the result". It is the only result. There is always precisely one result.
The x
you see is not a result of the evaluation. It simply happens to be shown as a side effect of evaluating Print
. But it is not what Print
evaluates to and cannot be used as an input to other functions. It is simply displayed when Print
is evaluated.
Echo[]
if you want the output to be the expression in addition to the printing. $\endgroup$Null
ref page says it is an indication of a result absence, the ref page ofPrint
says only things likePrint sends its output to the channel $Output.
- which isn't clear for newbies. There are a lot of examples of strage code withPrint
statements instead ofTable
etc, and I believe it's because its purpose is not well documented. $\endgroup$