Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / ref / print.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="ref.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="ref.html" title='Python Reference Manual' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="return.html" />
13<link rel="prev" href="del.html" />
14<link rel="parent" href="simple.html" />
15<link rel="next" href="return.html" />
16<meta name='aesop' content='information' />
17<title>6.6 The print statement </title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="6.5 The del statement"
25 href="del.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="6. Simple statements"
28 href="simple.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="6.7 The return statement"
31 href="return.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Reference Manual</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><img src='../icons/blank.png'
38 border='0' height='32' alt='' width='32' /></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="del.html">6.5 The del statement</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="simple.html">6. Simple statements</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="return.html">6.7 The return statement</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION008600000000000000000"></A><A NAME="print"></A>
56<BR>
576.6 The <tt class="keyword">print</tt> statement
58</H1>
59<a id='l2h-495' xml:id='l2h-495'></a>
60<P>
61<dl><dd class="grammar">
62<div class="productions">
63<table>
64<tr>
65 <td><a id='tok-print_stmt' xml:id='tok-print_stmt'>print_stmt</a></td>
66 <td>::=</td>
67 <td>"print" ( <big>[</big><a class='grammartoken' href="Booleans.html#tok-expression">expression</a> ("," <a class='grammartoken' href="Booleans.html#tok-expression">expression</a>)* <big>[</big>","<big>]</big><big>]</big></td></tr>
68 <tr>
69 <td></td>
70 <td></td>
71 <td><code>| "&gt;<code>&gt;</code>" <a class='grammartoken' href="Booleans.html#tok-expression">expression</a>
72 <big>[</big>("," <a class='grammartoken' href="Booleans.html#tok-expression">expression</a>)+ <big>[</big>","<big>]</big><big>]</big> )</code></td></tr>
73</table>
74</div>
75<a class="grammar-footer"
76 href="grammar.txt" type="text/plain"
77 >Download entire grammar as text.</a>
78</dd></dl>
79
80<P>
81<tt class="keyword">print</tt> evaluates each expression in turn and writes the
82resulting object to standard output (see below). If an object is not
83a string, it is first converted to a string using the rules for string
84conversions. The (resulting or original) string is then written. A
85space is written before each object is (converted and) written, unless
86the output system believes it is positioned at the beginning of a
87line. This is the case (1) when no characters have yet been written
88to standard output, (2) when the last character written to standard
89output is "<tt class="character">&#92;n</tt>", or (3) when the last write operation on
90standard output was not a <tt class="keyword">print</tt> statement. (In some cases
91it may be functional to write an empty string to standard output for
92this reason.) <span class="note"><b class="label">Note:</b>
93Objects which act like file objects but which are
94not the built-in file objects often do not properly emulate this
95aspect of the file object's behavior, so it is best not to rely on
96this.</span>
97<a id='l2h-503' xml:id='l2h-503'></a>
98<a id='l2h-496' xml:id='l2h-496'></a>
99<P>
100A "<tt class="character">&#92;n</tt>" character is written at the end, unless the
101<tt class="keyword">print</tt> statement ends with a comma. This is the only action
102if the statement contains just the keyword <tt class="keyword">print</tt>.
103<a id='l2h-497' xml:id='l2h-497'></a><a id='l2h-498' xml:id='l2h-498'></a>
104<P>
105Standard output is defined as the file object named <code>stdout</code>
106in the built-in module <tt class="module">sys</tt>. If no such object exists, or if
107it does not have a <tt class="method">write()</tt> method, a <tt class="exception">RuntimeError</tt>
108exception is raised.
109<a id='l2h-499' xml:id='l2h-499'></a><a id='l2h-504' xml:id='l2h-504'></a>
110<a id='l2h-501' xml:id='l2h-501'></a><a id='l2h-502' xml:id='l2h-502'></a>
111<P>
112<tt class="keyword">print</tt> also has an extended<a id='l2h-505' xml:id='l2h-505'></a>
113form, defined by the second portion of the syntax described above.
114This form is sometimes referred to as ``<tt class="keyword">print</tt> chevron.''
115In this form, the first expression after the <code>&gt;</code><code>&gt;</code> must
116evaluate to a ``file-like'' object, specifically an object that has a
117<tt class="method">write()</tt> method as described above. With this extended form,
118the subsequent expressions are printed to this file object. If the
119first expression evaluates to <code>None</code>, then <code>sys.stdout</code> is
120used as the file for output.
121
122<P>
123
124<DIV CLASS="navigation">
125<div class='online-navigation'>
126<p></p><hr />
127<table align="center" width="100%" cellpadding="0" cellspacing="2">
128<tr>
129<td class='online-navigation'><a rel="prev" title="6.5 The del statement"
130 href="del.html"><img src='../icons/previous.png'
131 border='0' height='32' alt='Previous Page' width='32' /></A></td>
132<td class='online-navigation'><a rel="parent" title="6. Simple statements"
133 href="simple.html"><img src='../icons/up.png'
134 border='0' height='32' alt='Up One Level' width='32' /></A></td>
135<td class='online-navigation'><a rel="next" title="6.7 The return statement"
136 href="return.html"><img src='../icons/next.png'
137 border='0' height='32' alt='Next Page' width='32' /></A></td>
138<td align="center" width="100%">Python Reference Manual</td>
139<td class='online-navigation'><a rel="contents" title="Table of Contents"
140 href="contents.html"><img src='../icons/contents.png'
141 border='0' height='32' alt='Contents' width='32' /></A></td>
142<td class='online-navigation'><img src='../icons/blank.png'
143 border='0' height='32' alt='' width='32' /></td>
144<td class='online-navigation'><a rel="index" title="Index"
145 href="genindex.html"><img src='../icons/index.png'
146 border='0' height='32' alt='Index' width='32' /></A></td>
147</tr></table>
148<div class='online-navigation'>
149<b class="navlabel">Previous:</b>
150<a class="sectref" rel="prev" href="del.html">6.5 The del statement</A>
151<b class="navlabel">Up:</b>
152<a class="sectref" rel="parent" href="simple.html">6. Simple statements</A>
153<b class="navlabel">Next:</b>
154<a class="sectref" rel="next" href="return.html">6.7 The return statement</A>
155</div>
156</div>
157<hr />
158<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
159</DIV>
160<!--End of Navigation Panel-->
161<ADDRESS>
162See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
163</ADDRESS>
164</BODY>
165</HTML>