Python built-ins

Built-in functions

The Python interpreter has a number of functions built into it that are always available. They are listed here in alphabetical order.

Built-in Functions
abs() divmod() input() open() staticmethod()
all() enumerate() int() ord() str()
any() eval() isinstance() pow() sum()
basestring() execfile() issubclass() print() super()
bin() file() iter() property() tuple()
bool() filter() len() range() type()
bytearray() float() list() raw_input() unichr()
callable() format() locals() reduce() unicode()
chr() frozenset() long() reload() vars()
classmethod() getattr() map() repr() xrange()
cmp() globals() max() reversed() zip()
compile() hasattr() memoryview() round() import()
complex() hash() min() set()
delattr() help() next() setattr()
dict() hex() object() slice()
dir() id() oct() sorted()

For a more detailed description of their usages please see a link python-bult-in-fncts. See also a list of Python built-in keywords Python keywords.

Easily, you can check their help pages using, for example, help(abs).

Built-in constants

The two most frequently used built-in constants in Python include:

Operation Result
False The false value of the bool type
True The true value of the bool type

For a more detailed description of built-in constants please see a link python-bult-in-constants.

Built-in types

Boolean operations

These are the Boolean operations, ordered by ascending priority:

Operation Result
x or y if x is false, then y, else x
x and y if x is false, then x, else y
not x if x is false, then True, else False

Comparisons

This table summarizes the comparison operations:

Operation Meaning
< strictly less than
<= less than or equal
> strictly greater than
>= greater than or equal
== equal
!= not equal
is object identity
is not negated object identity

Numerics

All built-in numeric types support the following operations.

Operation Result
x + y sum of x and y
x - y difference of x and y
x * y product of x and y
x / y quotient of x and y
x // y (floored) quotient of x and y
x % y remainder of x / y
-x x negated
+x x unchanged
abs(x) absolute value or magnitude of x
int(x) x converted to integer
long(x) x converted to long integer
float(x) x converted to floating point
complex(re,im) a complex number with real part re, imaginary part im. im defaults to zero.
c.conjugate() conjugate of the complex number c. (Identity on real numbers)
divmod(x, y) the pair (x // y, x % y)
pow(x, y) x to the power y
x ** y x to the power y

For a more detailed description of built-in types please see a link python-bult-in-types.

An example study

The following example shows how to use Python’s built in functions.

  • $lecture_note/chapters/chapt03/codes/examples/builtin.py