19 3.2. The standard type hierarchy The Python Language Reference, Release 3.9.5 Integers ($_{int}$) These represent numbers in an unlimited range, subject to available (virtual) memory only. For the purpose of shift and mask operations, a binary representation is assumed, and negative numbers are represented in a variant of 2’s complement which gives the illusion of an infinite string of sign bits extending to the left. Booleans ($_{bool}$) These represent the truth values False and True. The two objects representing the values$_{False}$ and$_{True}$ are the only Boolean objects. The Boolean type is a subtype of the integer type, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. numbers.Real ($_{float}$ ) These represent machine-level double precision floating point numbers. You are at the mercy of the underlying machine architecture (and C or Java implementation) for the accepted range and handling of overflow. Python does not support single-precision floating point numbers; the savings in processor and memory usage that are usually the reason for using these are dwarfed by the overhead of using objects in Python, so there is no reason to complicate the language with two kinds of floating point numbers. numbers.Complex ( complex ) These represent complex numbers as a pair of machine-level double pre- cision floating point numbers. The same caveats apply as for floating point numbers. The real and imag- inary parts of a complex number$_{z}$ can be retrieved through the read-only attributes$_{z.real}$and$_{z.}$ $_{imag}$. Sequences These represent finite ordered sets indexed by non-negative numbers. The built-in function$_{len()}$ returns the number of items of a sequence. When the length of a sequence is n , the index set contains the numbers 0, 1, …, n -1. Item i of sequence a is selected by$_{a[i]}$ . Immutable sequences An object of an immutable sequence type cannot change once it is created. (If the object contains references to other objects, these other objects may be mutable and may be changed; however, the collection of objects directly referenced by an immutable object cannot change.) Strings A string is a sequence of values that represent Unicode code points. All the code points in the range$_{U+0000 - U+10FFFF}$ can be represented in a string. Python doesn’t have a$_{char}$ type; instead, every code point in the string is represented as a string object with length$_{1}$ . The built-in function$_{ord()}$ converts a code point from its string form to an integer in the range$_{0}$ - 10FFFF ;$_{chr()}$ converts an integer in the range$_{0 - 10FFFF}$ to the corresponding length $_{1}$string object. str.encode() can be used to convert a$_{str}$ to$_{bytes}$ using the given text encoding, and$_{bytes.decode()}$ can be used to achieve the opposite. Tuples The items of a tuple are arbitrary Python objects. Tuples of two or more items are formed by comma-separated lists of expressions. A tuple of one item (a ‘singleton’) can be formed by affixing a comma to an expression (an expression by itself does not create a tuple, since parentheses must be usable for grouping of expressions). An empty tuple can be formed by an empty pair of parentheses. Bytes A bytes object is an immutable array. The items are 8-bit bytes, represented by integers in the range 0 <= x < 256. Bytes literals (like$_{b'abc'}$ ) and the built-in$_{bytes()}$ constructor can be used to create bytes objects. Also, bytes objects can be decoded to strings via the$_{decode()}$ method. Mutable sequences Mutable sequences can be changed after they are created. The subscription and slicing notations can be used as the target of assignment and$_{del}$(delete) statements. There are currently two intrinsic mutable sequence types: The following types are immutable sequences: Sequences are distinguished according to their mutability: Some sequences also support “extended slicing” with a third “step” parameter:$_{a[i:j:k]}$ selects all items of a with index x where$_{x = i + n*k}$ , n$_{>= 0}$ and i$_{<=}$ x$_{<}$j . Sequences also support slicing:$_{a[i:j]}$selects all items with index k such that i$_{<=}$ k$_{<}$j . When used as an expression, a slice is a sequence of the same type. This implies that the index set is renumbered so that it starts at 0. The rules for integer representation are intended to give the most meaningful interpretation of shift and mask operations involving negative integers.