Python Built-in Functions Functions

EditRocket provides the following information on Built-in Functions functions in the Python source code builder.

abs(x) - Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.

all(iterable) - Return True if all elements of the iterable are true.

any(iterable) - Return True if any element of the iterable is true.

basestring() - This abstract type is the superclass for str and unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str or unicode. isinstance(obj, basestring) is equivalent to isinstance(obj, (str, unicode)).

bool([x]) - Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.

callable(object) - Return true if the object argument appears callable, false if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.

chr(i) - Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range.

classmethod(function) - Return a class method for function.

cmp(x, y) - Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y.

compile(string, filename, kind[, flags[, dont_inherit]]) - Compile the string into a code object.

complex([real[, imag]]) - Create a complex number with the value real + imag*j or convert a string or number to a complex number.

delattr(object, name) - This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object's attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, 'foobar') is equivalent to del x.foobar.

dict([arg]) - Return a new dictionary initialized from an optional positional argument or from a set of keyword arguments. If no arguments are given, return a new empty dictionary. If the positional argument arg is a mapping object, return a dictionary mapping the same keys to the same values as does the mapping object. Otherwise the positional argument must be a sequence, a container that supports iteration, or an iterator object. The elements of the argument must each also be of one of those kinds, and each must in turn contain exactly two objects. The first is used as a key in the new dictionary, and the second as the key's value. If a given key is seen more than once, the last value associated with it is retained in the new dictionary.

dir([object]) - Without arguments, return the list of names in the current local symbol table. With an argument, attempts to return a list of valid attributes for that object.

divmod(a, b) - Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division.

enumerate(iterable) - Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration.

eval(expression[, globals[, locals]]) - The arguments are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.

execfile(filename[, globals[, locals]]) - Similar to exec, but parses a file instead of a string

file(filename[, mode[, bufsize]]) - Constructor function for the file type. When opening a file, it's preferable to use open() instead of invoking this constructor directly.

filter(function, iterable) - Construct a list from those elements of iterable for which function returns true.

float([x]) - Convert a string or a number to floating point.

frozenset([iterable]) - Return a frozenset object whose elements are taken from iterable.

getattr(object, name[, default]) - Return the value of the named attributed of object. name must be a string.

globals() - Return a dictionary representing the current global symbol table.

hasattr(object, name) - The result is True if the string is the name of one of the object's attributes, False if not.

hash(object) - Return the hash value of the object (if it has one).

help([object]) - Invoke the built-in help system.

hex(x) - Convert an integer number (of any size) to a hexadecimal string.

id(object) - Return the ``identity'' of an object.

input([prompt]) - Equivalent to eval(raw_input(prompt)).

int([x[, radix]]) - Convert a string or number to a plain integer.

isinstance(object, classinfo) - Return true if the object argument is an instance of the classinfo argument, or of a (direct or indirect) subclass thereof.

issubclass(class, classinfo) - Return true if class is a subclass (direct or indirect) of classinfo.

iter(o[, sentinel]) - Return an iterator object.

len(s) - Return the length (the number of items) of an object.

list([iterable]) - Return a list whose items are the same and in the same order as iterable's items.

locals() - Update and return a dictionary representing the current local symbol table.

long([x[, radix]]) - Convert a string or number to a long integer.

map(function, iterable, ...) - Apply function to every item of iterable and return a list of the results.

max(iterable[, args...][key]) - With a single argument iterable, return the largest item of a non-empty iterable (such as a string, tuple or list). With more than one argument, return the largest of the arguments.

min(iterable[, args...][key]) - With a single argument iterable, return the smallest item of a non-empty iterable (such as a string, tuple or list). With more than one argument, return the smallest of the arguments.

object() - Return a new featureless object.

oct(x) - Convert an integer number (of any size) to an octal string.

open(filename[, mode[, bufsize]]) - Open a file, returning an object of the file type.

ord(c) - Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string.

pow(x, y[, z]) - Return x to the power y; if z is present, return x to the power y, modulo z

property([fget[, fset[, fdel[, doc]]]]) - Return a property attribute for new-style classes (classes that derive from object).

range([start,] stop[, step]) - Create lists containing arithmetic progressions.

raw_input([prompt]) - If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.

reduce(function, iterable[, initializer]) - Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value.

reload(module) - Reload a previously imported module.

repr(object) - Return a string containing a printable representation of an object.

reversed(seq) - Return a reverse iterator.

round(x[, n]) - Return the floating point value x rounded to n digits after the decimal point. If n is omitted, it defaults to zero.

set([iterable]) - Return a set whose elements are taken from iterable. The elements must be immutable.

setattr(object, name, value) - This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value.

slice([start,] stop[, step]) - Return a slice object representing the set of indices specified by range(start, stop, step).

sorted(iterable[, cmp[, key[, reverse]]]) - Return a new sorted list from the items in iterable.

staticmethod(function) - Return a static method for function.

str([object]) - Return a string containing a nicely printable representation of an object.

sum(iterable[, start]) - Sums start and the items of an iterable from left to right and returns the total.

super(type[, object-or-type]) - Return the superclass of type.

tuple([iterable]) - Return a tuple whose items are the same and in the same order as iterable's items.

type(object) - Return the type of an object. The return value is a type object.

unichr(i) - Return the Unicode string of one character whose Unicode code is the integer i.

vars([object]) - Without arguments, return a dictionary corresponding to the current local symbol table. With a module, class or class instance object as argument (or anything else that has a __dict__ attribute), returns a dictionary corresponding to the object's symbol table.

xrange([start,] stop[, step]) - This function is very similar to range(), but returns an ``xrange object'' instead of a list.

zip([iterable, ...]) - This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.