Python Built-In Functions

Python ascii() Function

Returns a readable version of an object by replacing non-ASCII characters with an escape character.

Python abs() Function

Returns the absolute value of a number.

Python all() Function

Returns True if all items in an iterable object (a list, tuple, or dictionary) are True.

Python any() Function

Returns True if any items in an iterable (a list, tuple, or dictionary) are True. If the iterable is empty then this function returns False.

Python bin() Function

Returns the binary version of a number

Python bool() Function

Returns the boolean of a value. 0, False, None and an empty string return False. Anything else (a non-zero number, True, something with a value, and a non-empty string) return True.

Python bytearray() Function

Returns either an empty bytearray object of a given size, or a bytearray object from the bytes in the source object

Python bytes() Function

Returns an array of the specified number of bytes, initialized to 0. If a string is passed instead of a number, the string is encoded as bytes with the encoding (required parameter when converting strings to bytes).

Python callable() Function

Description

Python chr() Function

Returns the character (a string) of an integer representing a unicode code point.

Python compile() Function

The compile() converts a string to a Python code object. The code object is then executed using exec() function.

Python delattr() Function

Deletes an attribute of an object. Note that the attribute is deleted for the instance of that object, not for the class. Other instances (objects) of the same class still retain the attribute.

Python object() Function

Returns a featureless object.

Python oct() Function

Converts an integer to octal, a base 8 number.

Python open() Function

Opens a file for reading, writing or appending.

Python ord() Function

Given a string representing one Unicode character, ord() returns an integer representing the Unicode code point of that character.

Python pow() Function

Returns the value of x to the power of y, which is equivalent to using the ** operator, but note that the ** operator is usually faster.

Python print() Function

Prints a message to the screen or other standard output device.

Python property() Function

One can programmatically create a property of a class that references the getter, setter, and deleter functions for an attribute of the class, and optionally documentation for the attribute as well.

Python range() Function

Returns a sequence of numbers starting from 0 (the default) and incrementing by 1 (the default) to the specified stop value. The stop value is not included in the range.

Python repr() Function

Returns a printable representation of the given object.

Python reversed() Function

Returns a reversed iterator object.

Python round() Function

Rounds numbers to the specified number of digits past the decimal point (default is 0 digits past the decimal point.)

Python next() Function

The next() function returns the next item in an iterator. If the items in the collection are exhausted, Python throws a StopIteration exception.

Python set() Function

Returns a new set object which can either be an uninitialized set or from a sequence, collection, or iterator object.

Python slice() Function

Returns a slice object. A slice object is an object that is used to slice (cut up) any indexable collection (string, tuple, list, range, or bytes).

Python sorted() Function

Returns a sorted list, in ascending order or optionally in descending order. Contrast this with the sort() function, which does an in-place sort.

Python str() Function

Returns an object converted to a string.

Python sum() Function

Sums all the items in an iterator

Python super() Function

Returns an object that represents the parent instance which you can use to access functions in the parent class.

Python tuple() Function

Creates a tuple from a sequence, collection, or an iterable object. If the parameter is not specified, Python returns an empty tuple.

Python type() Function

Returns the type of an object.

Python vars() Function

Returns the attributes of a class as a dictionary. Contrast with the dir() function, which includes class attributes and the attributes of super classes as well.

Python zip() Function

Returns an iterable object of tuples that joins together two or more iteratable objects, pairing each item in the iterables. The iterable with the least items determines the length of the tuple.

Python setattr() Function

Sets the attribute of an object. The attribute must have been initialized in the class.

Python min() Function

Returns the smallest value in a list of parameters or in an iterable.

Python memoryview() Function

Returns a memory view of an object.

Python max() Function

Returns the largest value in a list of parameters or in an iterable.

Python dict() Function

Returns a dictionary from a comma separated list of key-value pairs.

Python dir() Function

Returns a list of the specified object's properties and methods. If no object is specified, dir() returns the list of names in the current local scope. The dir() function is provided primarily as a convenience for use at an interactive prompt, for example, asking what function the user would like to use.

Python divmod() Function

Returns the quotient and the remainder when the first parameter (the dividend) is divided by the second parameter (the divisor).

Python enumerate() Function

Takes a collection (lists, tuples, sets and dictionaries) and returns it is as an "enumerate object."  When using the enumerate object in a loop, each item in the enumerate object includes a counter, starting from 0 by default, and the value in the collection.

Python eval() Function

The eval() function evaluates and executes a Python code expression, returning the result of the expression.  

Python exec() Function

Executes a code block, expression to be evaluated, or single expression statement to be printed.

Python filter() Function

This function returns an iterator that yields the items that are either true, or items for which the filter function returns true.

Python float() Function

Converts a string or integer to a floating point number.

Python format() Function

The format method conerts a value to a string using the specified format. For example, ".2f" means, format the value to two numbers past the decimal point.

Python frozenset() Function

Returns an immutable (unchangeable) set. This is useful for when you want to prevent the set from being changed. In the following example, we see that an exception is thrown when trying to add another item to the frozenset object.

Python getattr() Function

Gets the value of an attribute of an object. While normally one just gets the value to an attribute (for example, name = person.name), in meta-programming, it can is often useful to be able to get an attribute by its name.

Python globals() Function

Returns a dictionary of the current global symbol table. In this example, we are filtering the globals to exclude Python defined globals, which always are preceded with '__'. This is often more useful, so you can see only the variables that you've created that are global.

Python hasattr() Function

Returns true if the object has the specified property or method.

Python hash() Function

Returns the hash value of the specified value if it has one. Numbers do not have a hash value other than the number itself. Hash values are used to improve the performance of key lookups, for example in a dictionary.

Python help() Function

Executes the built-in help system, which is an interactive way of getting help on Python functions.

Python hex() Function

Converts a number to its hexidecimal value.

Python id() Function

Returns a unique id for the specified object. This is useful to determine whether two values are in fact the same object.

Python input() Function

The input() function puts the user input into a variable.

Python isinstance() Function

Returns True if the object is an instance of the specified type, if not this function returns False.

Python issubclass() Function

Returns True if a class is a subclass of the specified class.

Python iter() Function

Returns an iterator object, which can be used to iterate over the collection. Because collections have built-in iterators, the iter() function applied to collections is not necessary, as the example demonstrates.

Python len() Function

Returns the length of an object. This is useful for determining the length of string or array and the the number of items in a collection (list, dictionary, set, or tuple.)

Python list() Function

Creates a List object from the supplied object.

Python locals() Function

Python map() Function

Returns an interator that applies the specified function to every item in the iterable (usually a collection), and yields the results.

Python complex() Function

Returns a complex number from either two numbers or a string. The real and imaginary components of the complex number can be accessed with the real and imag properties.