Next / Previous / Contents / TCC Help System / NM Tech homepage

22.8. The print statement: Display output values

Use this statement to display values on the standard output stream. General form:

print thing1, thing2, ...[,]

Each thing must be a string, or a value that can be converted into a string by the str() function (see Section 20.40, “str(): Convert to str type”). These strings are written to the standard output stream, with one space between each value. A print statement by itself prints an empty line.

>>> print 4.3, 'Sir Robin', 1./7
4.3 Sir Robin 0.142857142857
>>> for i in range(4):
...     print i**4,
0 1 16 81

Normally, a newline is printed after the last value. However, you can suppress this behavior by appending a comma to the end of the list. For example, this statement:

print 'State your name:',

would print the string followed by one space and leave the cursor at the end of that line.