Built-in Types

This section documents Python’s core built-in types, such as int, float, dict, and many others. More details about many of these types, and about operations on their instances, are found throughout Chapter 4. In the rest of this section, by “number” I mean, specifically, “noncomplex number.”

basestring

basestring

Noninstantiable (abstract) common basetype of types str and unicode. Used mostly to ascertain whether some object x is a string (either plain or Unicode) by testing isinstance(x, basestring).

bool

bool(x)

Returns False if argument x evaluates as false; returns True if argument x evaluates as true. (See also Boolean Values.) bool is a subclass of int, and built-in names False and True refer to the only two instances of type bool. These instances are also integer numbers, equal to 0 and 1, respectively, but str(True) is 'True', and str(False) is 'False'.

buffer

buffer(obj,offset=0,size=-1)

Returns a read-only buffer object that refers to a compact slice of obj’s data, starting at the given offset and with the given size (all the way to the end of obj’s data, if size<0, or if obj’s data is too short to provide size bytes after the offset). obj must be of a type that supports the buffer call interface, such as a string or array.

classmethod

classmethod(function)

Returns a class method object. In practice, you call this built-in type only within a class body, and, most often, in Python 2.4, you use it as a decorator. See Class methods.

complex

complex(real,imag=0)

Converts ...

Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.