You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Python interpreter supports many functions that are built-in: sixty-eight, as of Python 3.6. You will cover many of these in the following discussions, as they come up in context.
Math
Function
Description
abs()
Returns absolute value of a number
divmod()
Returns quotient and remainder of integer division
max()
Returns the largest of the given arguments or items in an iterable
min()
Returns the smallest of the given arguments or items in an iterable
pow()
Raises a number to a power
round()
Rounds a floating-point value
sum()
Sums the items of an iterable
Type Conversion
Function
Description
ascii()
Returns a string containing a printable representation of an object
bin()
Converts an integer to a binary string
bool()
Converts an argument to a Boolean value
chr()
Returns string representation of character given by integer argument
complex()
Returns a complex number constructed from arguments
float()
Returns a floating-point object constructed from a number or string
hex()
Converts an integer to a hexadecimal string
int()
Returns an integer object constructed from a number or string
oct()
Converts an integer to an octal string
ord()
Returns integer representation of a character
repr()
Returns a string containing a printable representation of an object
str()
Returns a string version of an object
type()
Returns the type of an object or creates a new type object
Iterables and Iterators
Function
Description
all()
Returns True if all elements of an iterable are true
any()
Returns True if any elements of an iterable are true
enumerate()
Returns a list of tuples containing indices and values from an iterable
filter()
Filters elements from an iterable
iter()
Returns an iterator object
len()
Returns the length of an object
map()
Applies a function to every item of an iterable
next()
Retrieves the next item from an iterator
range()
Generates a range of integer values
reversed()
Returns a reverse iterator
slice()
Returns a slice object
sorted()
Returns a sorted list from an iterable
zip()
Creates an iterator that aggregates elements from iterables
Composite Data Type
Function
Description
bytearray()
Creates and returns an object of the bytearray class
bytes()
Creates and returns a bytes object (similar to bytearray, but immutable)
dict()
Creates a dict object
frozenset()
Creates a frozenset object
list()
Constructs a list object
object()
Returns a new featureless object
set()
Creates a set object
tuple()
Creates a tuple object
Classes, Attributes, and Inheritance
Function
Description
classmethod()
Returns a class method for a function
delattr()
Deletes an attribute from an object
getattr()
Returns the value of a named attribute of an object
hasattr()
Returns True if an object has a given attribute
isinstance()
Determines whether an object is an instance of a given class
issubclass()
Determines whether a class is a subclass of a given class
property()
Returns a property value of a class
setattr()
Sets the value of a named attribute of an object
super()
Returns a proxy object that delegates method calls to a parent or sibling class
Input/Output
Function
Description
format()
Converts a value to a formatted representation
input()
Reads input from the console
open()
Opens a file and returns a file object
print()
Prints to a text stream or the console
Variables, References, and Scope
Function
Description
dir()
Returns a list of names in current local scope or a list of object attributes
globals()
Returns a dictionary representing the current global symbol table
id()
Returns the identity of an object
locals()
Updates and returns a dictionary representing current local symbol table
vars()
Returns dict attribute for a module, class, or object