Difference between revisions of "Print function"
(Created page with 'In Python, the '''print''' function prints things to the screen. More than one argument can be passed to print at a time. By default, multiple arguments are printed on the …') |
m |
||
Line 1: | Line 1: | ||
− | In [[Python]], the '''print''' function prints things to the screen. | + | In [[Python]], the '''print''' function prints things to the screen. In its simplest form it has the following syntax |
+ | print(arg1[,arg2[,...]]) | ||
More than one argument can be passed to print at a time. By default, multiple arguments are printed on the same line with a space inserted between each one and at the end of each print statement Python will insert a new line, so subsequent calls to print will output on consecutive lines. These default behaviors can be overridden, see the [http://docs.python.org/py3k/library/functions.html#print Python 3.2 Documentation] for details. | More than one argument can be passed to print at a time. By default, multiple arguments are printed on the same line with a space inserted between each one and at the end of each print statement Python will insert a new line, so subsequent calls to print will output on consecutive lines. These default behaviors can be overridden, see the [http://docs.python.org/py3k/library/functions.html#print Python 3.2 Documentation] for details. |
Revision as of 22:19, 10 March 2011
In Python, the print function prints things to the screen. In its simplest form it has the following syntax
print(arg1[,arg2[,...]])
More than one argument can be passed to print at a time. By default, multiple arguments are printed on the same line with a space inserted between each one and at the end of each print statement Python will insert a new line, so subsequent calls to print will output on consecutive lines. These default behaviors can be overridden, see the Python 3.2 Documentation for details.
If the arguments aren't already strings, print will convert them to strings just as str would.
By way of example, the following are some sample print statements, and their output
print(5) 5 print('this is a test') this is a test print('this','is','another','test') # note that spaces are inserted this is another test print('this'+'is'+'another'+'test') # no spaces are automatically inserted, because there is only one argument thisisanothertest print('The Answer is', 42) The Answer is 42