blob: 35e92cf9cb9f39eb2210e578a9f6ed0e846b6df1 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2.. _lexical:
3
4****************
5Lexical analysis
6****************
7
8.. index::
9 single: lexical analysis
10 single: parser
11 single: token
12
13A Python program is read by a *parser*. Input to the parser is a stream of
14*tokens*, generated by the *lexical analyzer*. This chapter describes how the
15lexical analyzer breaks a file into tokens.
16
17Python uses the 7-bit ASCII character set for program text.
18
19.. versionadded:: 2.3
20 An encoding declaration can be used to indicate that string literals and
21 comments use an encoding different from ASCII.
22
23For compatibility with older versions, Python only warns if it finds 8-bit
24characters; those warnings should be corrected by either declaring an explicit
25encoding, or using escape sequences if those bytes are binary data, instead of
26characters.
27
28The run-time character set depends on the I/O devices connected to the program
29but is generally a superset of ASCII.
30
31**Future compatibility note:** It may be tempting to assume that the character
32set for 8-bit characters is ISO Latin-1 (an ASCII superset that covers most
33western languages that use the Latin alphabet), but it is possible that in the
34future Unicode text editors will become common. These generally use the UTF-8
35encoding, which is also an ASCII superset, but with very different use for the
36characters with ordinals 128-255. While there is no consensus on this subject
37yet, it is unwise to assume either Latin-1 or UTF-8, even though the current
38implementation appears to favor Latin-1. This applies both to the source
39character set and the run-time character set.
40
41
42.. _line-structure:
43
44Line structure
45==============
46
47.. index:: single: line structure
48
49A Python program is divided into a number of *logical lines*.
50
51
52.. _logical:
53
54Logical lines
55-------------
56
57.. index::
58 single: logical line
59 single: physical line
60 single: line joining
61 single: NEWLINE token
62
63The end of a logical line is represented by the token NEWLINE. Statements
64cannot cross logical line boundaries except where NEWLINE is allowed by the
65syntax (e.g., between statements in compound statements). A logical line is
66constructed from one or more *physical lines* by following the explicit or
67implicit *line joining* rules.
68
69
70.. _physical:
71
72Physical lines
73--------------
74
75A physical line is a sequence of characters terminated by an end-of-line
76sequence. In source files, any of the standard platform line termination
77sequences can be used - the Unix form using ASCII LF (linefeed), the Windows
78form using the ASCII sequence CR LF (return followed by linefeed), or the
79Macintosh form using the ASCII CR (return) character. All of these forms can be
80used equally, regardless of platform.
81
82When embedding Python, source code strings should be passed to Python APIs using
83the standard C conventions for newline characters (the ``\n`` character,
84representing ASCII LF, is the line terminator).
85
86
87.. _comments:
88
89Comments
90--------
91
92.. index::
93 single: comment
94 single: hash character
95
96A comment starts with a hash character (``#``) that is not part of a string
97literal, and ends at the end of the physical line. A comment signifies the end
98of the logical line unless the implicit line joining rules are invoked. Comments
99are ignored by the syntax; they are not tokens.
100
101
102.. _encodings:
103
104Encoding declarations
105---------------------
106
107.. index::
108 single: source character set
109 single: encodings
110
111If a comment in the first or second line of the Python script matches the
112regular expression ``coding[=:]\s*([-\w.]+)``, this comment is processed as an
113encoding declaration; the first group of this expression names the encoding of
114the source code file. The recommended forms of this expression are ::
115
116 # -*- coding: <encoding-name> -*-
117
118which is recognized also by GNU Emacs, and ::
119
120 # vim:fileencoding=<encoding-name>
121
122which is recognized by Bram Moolenaar's VIM. In addition, if the first bytes of
123the file are the UTF-8 byte-order mark (``'\xef\xbb\xbf'``), the declared file
124encoding is UTF-8 (this is supported, among others, by Microsoft's
125:program:`notepad`).
126
127If an encoding is declared, the encoding name must be recognized by Python. The
128encoding is used for all lexical analysis, in particular to find the end of a
129string, and to interpret the contents of Unicode literals. String literals are
130converted to Unicode for syntactical analysis, then converted back to their
131original encoding before interpretation starts. The encoding declaration must
132appear on a line of its own.
133
134.. % XXX there should be a list of supported encodings.
135
136
137.. _explicit-joining:
138
139Explicit line joining
140---------------------
141
142.. index::
143 single: physical line
144 single: line joining
145 single: line continuation
146 single: backslash character
147
148Two or more physical lines may be joined into logical lines using backslash
149characters (``\``), as follows: when a physical line ends in a backslash that is
150not part of a string literal or comment, it is joined with the following forming
151a single logical line, deleting the backslash and the following end-of-line
152character. For example:
153
154.. %
155
156::
157
158 if 1900 < year < 2100 and 1 <= month <= 12 \
159 and 1 <= day <= 31 and 0 <= hour < 24 \
160 and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
161 return 1
162
163A line ending in a backslash cannot carry a comment. A backslash does not
164continue a comment. A backslash does not continue a token except for string
165literals (i.e., tokens other than string literals cannot be split across
166physical lines using a backslash). A backslash is illegal elsewhere on a line
167outside a string literal.
168
169
170.. _implicit-joining:
171
172Implicit line joining
173---------------------
174
175Expressions in parentheses, square brackets or curly braces can be split over
176more than one physical line without using backslashes. For example::
177
178 month_names = ['Januari', 'Februari', 'Maart', # These are the
179 'April', 'Mei', 'Juni', # Dutch names
180 'Juli', 'Augustus', 'September', # for the months
181 'Oktober', 'November', 'December'] # of the year
182
183Implicitly continued lines can carry comments. The indentation of the
184continuation lines is not important. Blank continuation lines are allowed.
185There is no NEWLINE token between implicit continuation lines. Implicitly
186continued lines can also occur within triple-quoted strings (see below); in that
187case they cannot carry comments.
188
189
190.. _blank-lines:
191
192Blank lines
193-----------
194
195.. index:: single: blank line
196
197A logical line that contains only spaces, tabs, formfeeds and possibly a
198comment, is ignored (i.e., no NEWLINE token is generated). During interactive
199input of statements, handling of a blank line may differ depending on the
200implementation of the read-eval-print loop. In the standard implementation, an
201entirely blank logical line (i.e. one containing not even whitespace or a
202comment) terminates a multi-line statement.
203
204
205.. _indentation:
206
207Indentation
208-----------
209
210.. index::
211 single: indentation
212 single: whitespace
213 single: leading whitespace
214 single: space
215 single: tab
216 single: grouping
217 single: statement grouping
218
219Leading whitespace (spaces and tabs) at the beginning of a logical line is used
220to compute the indentation level of the line, which in turn is used to determine
221the grouping of statements.
222
223First, tabs are replaced (from left to right) by one to eight spaces such that
224the total number of characters up to and including the replacement is a multiple
225of eight (this is intended to be the same rule as used by Unix). The total
226number of spaces preceding the first non-blank character then determines the
227line's indentation. Indentation cannot be split over multiple physical lines
228using backslashes; the whitespace up to the first backslash determines the
229indentation.
230
231**Cross-platform compatibility note:** because of the nature of text editors on
232non-UNIX platforms, it is unwise to use a mixture of spaces and tabs for the
233indentation in a single source file. It should also be noted that different
234platforms may explicitly limit the maximum indentation level.
235
236A formfeed character may be present at the start of the line; it will be ignored
237for the indentation calculations above. Formfeed characters occurring elsewhere
238in the leading whitespace have an undefined effect (for instance, they may reset
239the space count to zero).
240
241.. index::
242 single: INDENT token
243 single: DEDENT token
244
245The indentation levels of consecutive lines are used to generate INDENT and
246DEDENT tokens, using a stack, as follows.
247
248Before the first line of the file is read, a single zero is pushed on the stack;
249this will never be popped off again. The numbers pushed on the stack will
250always be strictly increasing from bottom to top. At the beginning of each
251logical line, the line's indentation level is compared to the top of the stack.
252If it is equal, nothing happens. If it is larger, it is pushed on the stack, and
253one INDENT token is generated. If it is smaller, it *must* be one of the
254numbers occurring on the stack; all numbers on the stack that are larger are
255popped off, and for each number popped off a DEDENT token is generated. At the
256end of the file, a DEDENT token is generated for each number remaining on the
257stack that is larger than zero.
258
259Here is an example of a correctly (though confusingly) indented piece of Python
260code::
261
262 def perm(l):
263 # Compute the list of all permutations of l
264 if len(l) <= 1:
265 return [l]
266 r = []
267 for i in range(len(l)):
268 s = l[:i] + l[i+1:]
269 p = perm(s)
270 for x in p:
271 r.append(l[i:i+1] + x)
272 return r
273
274The following example shows various indentation errors::
275
276 def perm(l): # error: first line indented
277 for i in range(len(l)): # error: not indented
278 s = l[:i] + l[i+1:]
279 p = perm(l[:i] + l[i+1:]) # error: unexpected indent
280 for x in p:
281 r.append(l[i:i+1] + x)
282 return r # error: inconsistent dedent
283
284(Actually, the first three errors are detected by the parser; only the last
285error is found by the lexical analyzer --- the indentation of ``return r`` does
286not match a level popped off the stack.)
287
288
289.. _whitespace:
290
291Whitespace between tokens
292-------------------------
293
294Except at the beginning of a logical line or in string literals, the whitespace
295characters space, tab and formfeed can be used interchangeably to separate
296tokens. Whitespace is needed between two tokens only if their concatenation
297could otherwise be interpreted as a different token (e.g., ab is one token, but
298a b is two tokens).
299
300
301.. _other-tokens:
302
303Other tokens
304============
305
306Besides NEWLINE, INDENT and DEDENT, the following categories of tokens exist:
307*identifiers*, *keywords*, *literals*, *operators*, and *delimiters*. Whitespace
308characters (other than line terminators, discussed earlier) are not tokens, but
309serve to delimit tokens. Where ambiguity exists, a token comprises the longest
310possible string that forms a legal token, when read from left to right.
311
312
313.. _identifiers:
314
315Identifiers and keywords
316========================
317
318.. index::
319 single: identifier
320 single: name
321
322Identifiers (also referred to as *names*) are described by the following lexical
323definitions:
324
325.. productionlist::
326 identifier: (`letter`|"_") (`letter` | `digit` | "_")*
327 letter: `lowercase` | `uppercase`
328 lowercase: "a"..."z"
329 uppercase: "A"..."Z"
330 digit: "0"..."9"
331
332Identifiers are unlimited in length. Case is significant.
333
334
335.. _keywords:
336
337Keywords
338--------
339
340.. index::
341 single: keyword
342 single: reserved word
343
344The following identifiers are used as reserved words, or *keywords* of the
345language, and cannot be used as ordinary identifiers. They must be spelled
346exactly as written here::
347
348 and def for is raise
349 as del from lambda return
350 assert elif global not try
351 break else if or while
352 class except import pass with
353 continue finally in print yield
354
355.. versionchanged:: 2.4
356 :const:`None` became a constant and is now recognized by the compiler as a name
357 for the built-in object :const:`None`. Although it is not a keyword, you cannot
358 assign a different object to it.
359
360.. versionchanged:: 2.5
361 Both :keyword:`as` and :keyword:`with` are only recognized when the
362 ``with_statement`` future feature has been enabled. It will always be enabled in
363 Python 2.6. See section :ref:`with` for details. Note that using :keyword:`as`
364 and :keyword:`with` as identifiers will always issue a warning, even when the
365 ``with_statement`` future directive is not in effect.
366
367
368.. _id-classes:
369
370Reserved classes of identifiers
371-------------------------------
372
373Certain classes of identifiers (besides keywords) have special meanings. These
374classes are identified by the patterns of leading and trailing underscore
375characters:
376
377``_*``
378 Not imported by ``from module import *``. The special identifier ``_`` is used
379 in the interactive interpreter to store the result of the last evaluation; it is
380 stored in the :mod:`__builtin__` module. When not in interactive mode, ``_``
381 has no special meaning and is not defined. See section :ref:`import`.
382
383 .. note::
384
385 The name ``_`` is often used in conjunction with internationalization;
386 refer to the documentation for the :mod:`gettext` module for more
387 information on this convention.
388
389``__*__``
390 System-defined names. These names are defined by the interpreter and its
391 implementation (including the standard library); applications should not expect
392 to define additional names using this convention. The set of names of this
393 class defined by Python may be extended in future versions. See section
394 :ref:`specialnames`.
395
396``__*``
397 Class-private names. Names in this category, when used within the context of a
398 class definition, are re-written to use a mangled form to help avoid name
399 clashes between "private" attributes of base and derived classes. See section
400 :ref:`atom-identifiers`.
401
402
403.. _literals:
404
405Literals
406========
407
408.. index::
409 single: literal
410 single: constant
411
412Literals are notations for constant values of some built-in types.
413
414
415.. _strings:
416
417String literals
418---------------
419
420.. index:: single: string literal
421
422String literals are described by the following lexical definitions:
423
424.. index:: single: ASCII@ASCII
425
426.. productionlist::
427 stringliteral: [`stringprefix`](`shortstring` | `longstring`)
428 stringprefix: "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR"
429 shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"'
430 longstring: ""'" `longstringitem`* ""'"
431 : | '"""' `longstringitem`* '"""'
432 shortstringitem: `shortstringchar` | `escapeseq`
433 longstringitem: `longstringchar` | `escapeseq`
434 shortstringchar: <any source character except "\" or newline or the quote>
435 longstringchar: <any source character except "\">
436 escapeseq: "\" <any ASCII character>
437
438One syntactic restriction not indicated by these productions is that whitespace
439is not allowed between the :token:`stringprefix` and the rest of the string
440literal. The source character set is defined by the encoding declaration; it is
441ASCII if no encoding declaration is given in the source file; see section
442:ref:`encodings`.
443
444.. index::
445 single: triple-quoted string
446 single: Unicode Consortium
447 single: string; Unicode
448 single: raw string
449
450In plain English: String literals can be enclosed in matching single quotes
451(``'``) or double quotes (``"``). They can also be enclosed in matching groups
452of three single or double quotes (these are generally referred to as
453*triple-quoted strings*). The backslash (``\``) character is used to escape
454characters that otherwise have a special meaning, such as newline, backslash
455itself, or the quote character. String literals may optionally be prefixed with
456a letter ``'r'`` or ``'R'``; such strings are called :dfn:`raw strings` and use
457different rules for interpreting backslash escape sequences. A prefix of
458``'u'`` or ``'U'`` makes the string a Unicode string. Unicode strings use the
459Unicode character set as defined by the Unicode Consortium and ISO 10646. Some
460additional escape sequences, described below, are available in Unicode strings.
461The two prefix characters may be combined; in this case, ``'u'`` must appear
462before ``'r'``.
463
464In triple-quoted strings, unescaped newlines and quotes are allowed (and are
465retained), except that three unescaped quotes in a row terminate the string. (A
466"quote" is the character used to open the string, i.e. either ``'`` or ``"``.)
467
468.. index::
469 single: physical line
470 single: escape sequence
471 single: Standard C
472 single: C
473
474Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in strings are
475interpreted according to rules similar to those used by Standard C. The
476recognized escape sequences are:
477
478+-----------------+---------------------------------+-------+
479| Escape Sequence | Meaning | Notes |
480+=================+=================================+=======+
481| ``\newline`` | Ignored | |
482+-----------------+---------------------------------+-------+
483| ``\\`` | Backslash (``\``) | |
484+-----------------+---------------------------------+-------+
485| ``\'`` | Single quote (``'``) | |
486+-----------------+---------------------------------+-------+
487| ``\"`` | Double quote (``"``) | |
488+-----------------+---------------------------------+-------+
489| ``\a`` | ASCII Bell (BEL) | |
490+-----------------+---------------------------------+-------+
491| ``\b`` | ASCII Backspace (BS) | |
492+-----------------+---------------------------------+-------+
493| ``\f`` | ASCII Formfeed (FF) | |
494+-----------------+---------------------------------+-------+
495| ``\n`` | ASCII Linefeed (LF) | |
496+-----------------+---------------------------------+-------+
497| ``\N{name}`` | Character named *name* in the | |
498| | Unicode database (Unicode only) | |
499+-----------------+---------------------------------+-------+
500| ``\r`` | ASCII Carriage Return (CR) | |
501+-----------------+---------------------------------+-------+
502| ``\t`` | ASCII Horizontal Tab (TAB) | |
503+-----------------+---------------------------------+-------+
504| ``\uxxxx`` | Character with 16-bit hex value | \(1) |
505| | *xxxx* (Unicode only) | |
506+-----------------+---------------------------------+-------+
507| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(2) |
508| | *xxxxxxxx* (Unicode only) | |
509+-----------------+---------------------------------+-------+
510| ``\v`` | ASCII Vertical Tab (VT) | |
511+-----------------+---------------------------------+-------+
512| ``\ooo`` | Character with octal value | (3,5) |
513| | *ooo* | |
514+-----------------+---------------------------------+-------+
515| ``\xhh`` | Character with hex value *hh* | (4,5) |
516+-----------------+---------------------------------+-------+
517
518.. index:: single: ASCII@ASCII
519
520Notes:
521
522(1)
523 Individual code units which form parts of a surrogate pair can be encoded using
524 this escape sequence.
525
526(2)
527 Any Unicode character can be encoded this way, but characters outside the Basic
528 Multilingual Plane (BMP) will be encoded using a surrogate pair if Python is
529 compiled to use 16-bit code units (the default). Individual code units which
530 form parts of a surrogate pair can be encoded using this escape sequence.
531
532(3)
533 As in Standard C, up to three octal digits are accepted.
534
535(4)
536 Unlike in Standard C, at most two hex digits are accepted.
537
538(5)
539 In a string literal, hexadecimal and octal escapes denote the byte with the
540 given value; it is not necessary that the byte encodes a character in the source
541 character set. In a Unicode literal, these escapes denote a Unicode character
542 with the given value.
543
544.. index:: single: unrecognized escape sequence
545
546Unlike Standard C, all unrecognized escape sequences are left in the string
547unchanged, i.e., *the backslash is left in the string*. (This behavior is
548useful when debugging: if an escape sequence is mistyped, the resulting output
549is more easily recognized as broken.) It is also important to note that the
550escape sequences marked as "(Unicode only)" in the table above fall into the
551category of unrecognized escapes for non-Unicode string literals.
552
553When an ``'r'`` or ``'R'`` prefix is present, a character following a backslash
554is included in the string without change, and *all backslashes are left in the
555string*. For example, the string literal ``r"\n"`` consists of two characters:
556a backslash and a lowercase ``'n'``. String quotes can be escaped with a
557backslash, but the backslash remains in the string; for example, ``r"\""`` is a
558valid string literal consisting of two characters: a backslash and a double
559quote; ``r"\"`` is not a valid string literal (even a raw string cannot end in
560an odd number of backslashes). Specifically, *a raw string cannot end in a
561single backslash* (since the backslash would escape the following quote
562character). Note also that a single backslash followed by a newline is
563interpreted as those two characters as part of the string, *not* as a line
564continuation.
565
566When an ``'r'`` or ``'R'`` prefix is used in conjunction with a ``'u'`` or
567``'U'`` prefix, then the ``\uXXXX`` and ``\UXXXXXXXX`` escape sequences are
568processed while *all other backslashes are left in the string*. For example,
569the string literal ``ur"\u0062\n"`` consists of three Unicode characters: 'LATIN
570SMALL LETTER B', 'REVERSE SOLIDUS', and 'LATIN SMALL LETTER N'. Backslashes can
571be escaped with a preceding backslash; however, both remain in the string. As a
572result, ``\uXXXX`` escape sequences are only recognized when there are an odd
573number of backslashes.
574
575
576.. _string-catenation:
577
578String literal concatenation
579----------------------------
580
581Multiple adjacent string literals (delimited by whitespace), possibly using
582different quoting conventions, are allowed, and their meaning is the same as
583their concatenation. Thus, ``"hello" 'world'`` is equivalent to
584``"helloworld"``. This feature can be used to reduce the number of backslashes
585needed, to split long strings conveniently across long lines, or even to add
586comments to parts of strings, for example::
587
588 re.compile("[A-Za-z_]" # letter or underscore
589 "[A-Za-z0-9_]*" # letter, digit or underscore
590 )
591
592Note that this feature is defined at the syntactical level, but implemented at
593compile time. The '+' operator must be used to concatenate string expressions
594at run time. Also note that literal concatenation can use different quoting
595styles for each component (even mixing raw strings and triple quoted strings).
596
597
598.. _numbers:
599
600Numeric literals
601----------------
602
603.. index::
604 single: number
605 single: numeric literal
606 single: integer literal
607 single: plain integer literal
608 single: long integer literal
609 single: floating point literal
610 single: hexadecimal literal
611 single: octal literal
612 single: binary literal
613 single: decimal literal
614 single: imaginary literal
615 single: complex; literal
616
617There are four types of numeric literals: plain integers, long integers,
618floating point numbers, and imaginary numbers. There are no complex literals
619(complex numbers can be formed by adding a real number and an imaginary number).
620
621Note that numeric literals do not include a sign; a phrase like ``-1`` is
622actually an expression composed of the unary operator '``-``' and the literal
623``1``.
624
625
626.. _integers:
627
628Integer literals
629----------------
630
631Integer literals are described by the following lexical definitions:
632
633.. productionlist::
634 integer: `decimalinteger` | `octinteger` | `hexinteger`
635 decimalinteger: `nonzerodigit` `digit`* | "0"+
636 octinteger: "0" ("o" | "O") `octdigit`+
637 hexinteger: "0" ("x" | "X") `hexdigit`+
638 bininteger: "0" ("b" | "B") `bindigit`+
639 nonzerodigit: "1"..."9"
640 octdigit: "0"..."7"
641 hexdigit: `digit` | "a"..."f" | "A"..."F"
642 bindigit: "0"..."1"
643
644Plain integer literals that are above the largest representable plain integer
645(e.g., 2147483647 when using 32-bit arithmetic) are accepted as if they were
646long integers instead. [#]_ There is no limit for long integer literals apart
647from what can be stored in available memory.
648
649Note that leading zeros in a non-zero decimal number are not allowed. This is
650for disambiguation with C-style octal literals, which Python used before version
6513.0.
652
653Some examples of integer literals::
654
655 7 2147483647 0o177 0b100110111
656 3 79228162514264337593543950336 0o377 0x100000000
657 79228162514264337593543950336 0xdeadbeef
658
659
660.. _floating:
661
662Floating point literals
663-----------------------
664
665Floating point literals are described by the following lexical definitions:
666
667.. productionlist::
668 floatnumber: `pointfloat` | `exponentfloat`
669 pointfloat: [`intpart`] `fraction` | `intpart` "."
670 exponentfloat: (`intpart` | `pointfloat`) `exponent`
671 intpart: `digit`+
672 fraction: "." `digit`+
673 exponent: ("e" | "E") ["+" | "-"] `digit`+
674
675Note that the integer and exponent parts are always interpreted using radix 10.
676For example, ``077e010`` is legal, and denotes the same number as ``77e10``. The
677allowed range of floating point literals is implementation-dependent. Some
678examples of floating point literals::
679
680 3.14 10. .001 1e100 3.14e-10 0e0
681
682Note that numeric literals do not include a sign; a phrase like ``-1`` is
683actually an expression composed of the unary operator ``-`` and the literal
684``1``.
685
686
687.. _imaginary:
688
689Imaginary literals
690------------------
691
692Imaginary literals are described by the following lexical definitions:
693
694.. productionlist::
695 imagnumber: (`floatnumber` | `intpart`) ("j" | "J")
696
697An imaginary literal yields a complex number with a real part of 0.0. Complex
698numbers are represented as a pair of floating point numbers and have the same
699restrictions on their range. To create a complex number with a nonzero real
700part, add a floating point number to it, e.g., ``(3+4j)``. Some examples of
701imaginary literals::
702
703 3.14j 10.j 10j .001j 1e100j 3.14e-10j
704
705
706.. _operators:
707
708Operators
709=========
710
711.. index:: single: operators
712
713The following tokens are operators::
714
715 + - * ** / // %
716 << >> & | ^ ~
717 < > <= >= == !=
718
719
720.. _delimiters:
721
722Delimiters
723==========
724
725.. index:: single: delimiters
726
727The following tokens serve as delimiters in the grammar::
728
729 ( ) [ ] { } @
730 , : . ` = ;
731 += -= *= /= //= %=
732 &= |= ^= >>= <<= **=
733
734The period can also occur in floating-point and imaginary literals. A sequence
735of three periods has a special meaning as an ellipsis in slices. The second half
736of the list, the augmented assignment operators, serve lexically as delimiters,
737but also perform an operation.
738
739The following printing ASCII characters have special meaning as part of other
740tokens or are otherwise significant to the lexical analyzer::
741
742 ' " # \
743
744.. index:: single: ASCII@ASCII
745
746The following printing ASCII characters are not used in Python. Their
747occurrence outside string literals and comments is an unconditional error::
748
749 $ ?
750
751.. rubric:: Footnotes
752
753.. [#] In versions of Python prior to 2.4, octal and hexadecimal literals in the range
754 just above the largest representable plain integer but below the largest
755 unsigned 32-bit number (on a machine using 32-bit arithmetic), 4294967296, were
756 taken as the negative plain integer obtained by subtracting 4294967296 from
757 their unsigned value.
758