
12
|
Python Pocket Reference
0177, 0x9ff
Octal and hex integer constants
3+4j, 3.0+4.0j, 3J
Complex numbers
Operations
Number types support all number operations (see Table 6,
earlier in this book). In mixed-type expressions, Python con-
verts operands up to the type of the “highest” type, where
integer is lower than long, which is lower than floating-point,
which is lower than complex.
In Version 2.2 and later, integer results are automatically
promoted to longs instead of overflowing, so there is no need
to manually code an integer with a trailing letter “L” to force
long precision. Also, in Version 2.2 and later, there are two
flavors of division (
/ and //).
Strings
Strings are immutable (i.e., unchangeable) arrays of charac-
ters, accessed by offset.
Literals
Strings are written as a series of characters in quotes.
"Python's", 'Python"s'
Double and single quotes work the same, and each can
embed unescaped quotes of the other kind.
"""This is a
multiline block"""
Triple-quoted blocks collect lines into a single string,
with end-of-line markers (
\n) inserted between the origi-
nal lines.