Commit | Line | Data |
---|---|---|
920dae64 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="floating.html" /> | |
13 | <link rel="prev" href="numbers.html" /> | |
14 | <link rel="parent" href="literals.html" /> | |
15 | <link rel="next" href="floating.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>2.4.4 Integer and long integer literals</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="2.4.3 Numeric literals" | |
25 | href="numbers.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="2.4 Literals" | |
28 | href="literals.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="2.4.5 Floating point literals" | |
31 | href="floating.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="numbers.html">2.4.3 Numeric literals</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="literals.html">2.4 Literals</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="floating.html">2.4.5 Floating point literals</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION004440000000000000000"></A><A NAME="integers"></A> | |
56 | <BR> | |
57 | 2.4.4 Integer and long integer literals | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | Integer and long integer literals are described by the following | |
62 | lexical definitions: | |
63 | ||
64 | <P> | |
65 | <dl><dd class="grammar"> | |
66 | <div class="productions"> | |
67 | <table> | |
68 | <tr> | |
69 | <td><a id='tok-longinteger' xml:id='tok-longinteger'>longinteger</a></td> | |
70 | <td>::=</td> | |
71 | <td><a class='grammartoken' href="integers.html#tok-integer">integer</a> ("l" | "L")</td></tr> | |
72 | <tr> | |
73 | <td><a id='tok-integer' xml:id='tok-integer'>integer</a></td> | |
74 | <td>::=</td> | |
75 | <td><a class='grammartoken' href="integers.html#tok-decimalinteger">decimalinteger</a> | <a class='grammartoken' href="integers.html#tok-octinteger">octinteger</a> | <a class='grammartoken' href="integers.html#tok-hexinteger">hexinteger</a></td></tr> | |
76 | <tr> | |
77 | <td><a id='tok-decimalinteger' xml:id='tok-decimalinteger'>decimalinteger</a></td> | |
78 | <td>::=</td> | |
79 | <td><a class='grammartoken' href="integers.html#tok-nonzerodigit">nonzerodigit</a> <a class='grammartoken' href="identifiers.html#tok-digit">digit</a>* | "0"</td></tr> | |
80 | <tr> | |
81 | <td><a id='tok-octinteger' xml:id='tok-octinteger'>octinteger</a></td> | |
82 | <td>::=</td> | |
83 | <td>"0" <a class='grammartoken' href="integers.html#tok-octdigit">octdigit</a>+</td></tr> | |
84 | <tr> | |
85 | <td><a id='tok-hexinteger' xml:id='tok-hexinteger'>hexinteger</a></td> | |
86 | <td>::=</td> | |
87 | <td>"0" ("x" | "X") <a class='grammartoken' href="integers.html#tok-hexdigit">hexdigit</a>+</td></tr> | |
88 | <tr> | |
89 | <td><a id='tok-nonzerodigit' xml:id='tok-nonzerodigit'>nonzerodigit</a></td> | |
90 | <td>::=</td> | |
91 | <td>"1"..."9"</td></tr> | |
92 | <tr> | |
93 | <td><a id='tok-octdigit' xml:id='tok-octdigit'>octdigit</a></td> | |
94 | <td>::=</td> | |
95 | <td>"0"..."7"</td></tr> | |
96 | <tr> | |
97 | <td><a id='tok-hexdigit' xml:id='tok-hexdigit'>hexdigit</a></td> | |
98 | <td>::=</td> | |
99 | <td><a class='grammartoken' href="identifiers.html#tok-digit">digit</a> | "a"..."f" | "A"..."F"</td></tr> | |
100 | </table> | |
101 | </div> | |
102 | <a class="grammar-footer" | |
103 | href="grammar.txt" type="text/plain" | |
104 | >Download entire grammar as text.</a> | |
105 | </dd></dl> | |
106 | ||
107 | <P> | |
108 | Although both lower case "<tt class="character">l</tt>" and upper case "<tt class="character">L</tt>" are | |
109 | allowed as suffix for long integers, it is strongly recommended to always | |
110 | use "<tt class="character">L</tt>", since the letter "<tt class="character">l</tt>" looks too much like the | |
111 | digit "<tt class="character">1</tt>". | |
112 | ||
113 | <P> | |
114 | Plain integer literals that are above the largest representable plain | |
115 | integer (e.g., 2147483647 when using 32-bit arithmetic) are accepted | |
116 | as if they were long integers instead.<A NAME="tex2html1" | |
117 | HREF="#foot461"><SUP>2.1</SUP></A> There is no limit for long integer | |
118 | literals apart from what can be stored in available memory. | |
119 | ||
120 | <P> | |
121 | Some examples of plain integer literals (first row) and long integer | |
122 | literals (second and third rows): | |
123 | ||
124 | <P> | |
125 | <div class="verbatim"><pre> | |
126 | 7 2147483647 0177 | |
127 | 3L 79228162514264337593543950336L 0377L 0x100000000L | |
128 | 79228162514264337593543950336 0xdeadbeef | |
129 | </pre></div> | |
130 | ||
131 | <P> | |
132 | <BR><HR><H4>Footnotes</H4> | |
133 | <DL> | |
134 | <DT><A NAME="foot461">... instead.</A><A | |
135 | href="integers.html#tex2html1"><SUP>2.1</SUP></A></DT> | |
136 | <DD>In versions of Python | |
137 | prior to 2.4, octal and hexadecimal literals in the range just above | |
138 | the largest representable plain integer but below the largest unsigned | |
139 | 32-bit number (on a machine using 32-bit arithmetic), 4294967296, were | |
140 | taken as the negative plain integer obtained by subtracting 4294967296 | |
141 | from their unsigned value. | |
142 | ||
143 | </DD> | |
144 | </DL> | |
145 | <DIV CLASS="navigation"> | |
146 | <div class='online-navigation'> | |
147 | <p></p><hr /> | |
148 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
149 | <tr> | |
150 | <td class='online-navigation'><a rel="prev" title="2.4.3 Numeric literals" | |
151 | href="numbers.html"><img src='../icons/previous.png' | |
152 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
153 | <td class='online-navigation'><a rel="parent" title="2.4 Literals" | |
154 | href="literals.html"><img src='../icons/up.png' | |
155 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
156 | <td class='online-navigation'><a rel="next" title="2.4.5 Floating point literals" | |
157 | href="floating.html"><img src='../icons/next.png' | |
158 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
159 | <td align="center" width="100%">Python Reference Manual</td> | |
160 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
161 | href="contents.html"><img src='../icons/contents.png' | |
162 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
163 | <td class='online-navigation'><img src='../icons/blank.png' | |
164 | border='0' height='32' alt='' width='32' /></td> | |
165 | <td class='online-navigation'><a rel="index" title="Index" | |
166 | href="genindex.html"><img src='../icons/index.png' | |
167 | border='0' height='32' alt='Index' width='32' /></A></td> | |
168 | </tr></table> | |
169 | <div class='online-navigation'> | |
170 | <b class="navlabel">Previous:</b> | |
171 | <a class="sectref" rel="prev" href="numbers.html">2.4.3 Numeric literals</A> | |
172 | <b class="navlabel">Up:</b> | |
173 | <a class="sectref" rel="parent" href="literals.html">2.4 Literals</A> | |
174 | <b class="navlabel">Next:</b> | |
175 | <a class="sectref" rel="next" href="floating.html">2.4.5 Floating point literals</A> | |
176 | </div> | |
177 | </div> | |
178 | <hr /> | |
179 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
180 | </DIV> | |
181 | <!--End of Navigation Panel--> | |
182 | <ADDRESS> | |
183 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
184 | </ADDRESS> | |
185 | </BODY> | |
186 | </HTML> |