This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / Textual Input and Output /

2.9.18 Generating Unstructured Output

The functions described so far in this section determine how expressions should be formatted when they are printed, but they do not actually cause anything to be printed.

In the most common way of using Mathematica you never in fact explicitly have to issue a command to generate output. Usually, Mathematica automatically prints out the final result that it gets from processing input you gave. Sometimes, however, you may want to get Mathematica to print out expressions at intermediate stages in its operation. You can do this using the function Print.

Printing expressions.

Print prints its arguments, with no spaces in between, but with a newline (line feed) at the end.

In[1]:= Print[a, b]; Print[c]

This prints a table of the first five integers and their squares.

In[2]:= Do[Print[i, " ", i^2], {i, 5}]

Print simply takes the arguments you give, and prints them out one after the other, with no spaces in between. In many cases, you will need to print output in a more complicated format. You can do this by giving an output form as an argument to Print.

This prints the matrix in the form of a table.

In[3]:= Print[TableForm[{{1, 2}, {3, 4}}]]

Here the output format is specified using StringForm.

In[4]:= Print[StringForm["x = ``, y = ``", a^2, b^2]]

The output generated by Print is usually given in the standard Mathematica output format. You can however explicitly specify that some other output format should be used.

This prints output in Mathematica input form.

In[5]:= Print[InputForm[a^2 + b^2]]

You should realize that Print is only one of several mechanisms available in Mathematica for generating output. Another is the function Message described in Section 2.9.21, used for generating named messages. There are also a variety of lower-level functions described in Section 2.12.3 which allow you to produce output in various formats both as part of an interactive session, and for files and external programs.