Built-in Functions Flashcards
Summaries of all built-in functions
abs(x)
Return the absolute value of a number.
aiter(async_iterable)
Return an asynchronous iterator for an asynchronous iterable.
all(iterable)
Return true if all elements of the iterable are true or if the iterable is empty.
anext(async_iterator[,default])
When awaited, return the next item from the given asynchronous iterator, or default if given and the iterator is exhausted.
any(iterable)
Return true if any element of the iterable is true. If the iterable is empty, return False.
ascii(object)
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u, or \U escapes.
bin(x)
Convert an integer number to a binary string prefixed with “0b”.
bool([x])
Return a boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure.
breakpoint(*args, **kws)
Drops you into the debugger at the call site.
bytearray([source[, encoding[, errors]]])
Return a new array of bytes.
bytes([source[, encoding[, errors]]])
Return a new “bytes” object which is an immutable sequence of integers in the range 0 <= x < 256.
callable(object)
Return True if the object argument appears callable, False if not.
chr(i)
Return the string representing a character whose Unicode code point is the integer i.
@classmethod
Transform a method into a class method.
compile(source, filename, mode, flags=0, dont_inherit_False, optimize=- 1)
Compile the source into a code or AST object.
complex([real[, imag]])
Return a complex number with the value real + imag*1j or convert a string or number to a complex number.
delattr(object, name)
Deletes the named attribute, provided the object allows it. This is a relative of setattr().
dict(**kwarg)
dict(mapping, **kwarg)
dict(iterable, **kwarg)
Create a new dictionary.
dir([object])
Without arguments, return the list of names in the current local scope. With an argument, attempt 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 integer division.
enumerate(iterable, start=0)
Return an enumerate object.
eval(expression[, globals[, locals]])
Returns the result of the evaluated expression.
exec(object[, globals[, locals]])
This function supports dynamic execution of Python code.
filter(function, iterable)
Construct an iterator from those elements of iterable for which function returns True.
float([x])
Return a floating point number constructed from a number or string x.
format(value[, format_spec})
Convert a value to a “formatted” representation, as controlled by format_spec.
frozenset([iterable})
Return a new frozenset object, optionally with elements taken from iterable.
getattr(object, name[, default])
Return the value of the named attribute of object.
globals()
Return the dictionary implementing the current module namespace.
hasattr(object, name)
Returns 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.
help([object])
Invoke the built-in help system.
hex(x)
Convert an integer number to a lowercase hexadecimal string prefixed with “0x”
id(object)
Return the “identity” of an object.
input([prompt])
Gets console input from the user, reads a line from input, converts it to a string, and returns it.
int([x])
int(x, base=10)
Returns an integer object constructed from a number or string x, or return 0 if no arguments are given.
isinstance(object, classinfo)
Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtual) subclass thereof.
issubclass(class, classinfo)
Return True if class is a subclass (direct, indirect, or virtual) of classinfo.
iter(object[, sentinel])
Return an iterator object.
len(s)
Return the length (the number of items) of an object.
locals()
Update and return a dictionary representing the current local symbol table.
map(function, iterable, …)
Return an iterator that applies function to every item of iterable, yielding the results.
max(iterable, *[, key, default])
max(arg1, arg2, *args[,key])
Return the largest item in an iterable or the largest of two or more arguments.
memoryview(object)
Return a “memory view” object created from the given argument.
min(iterable, *[, key, default])
min(arg1, arg2, *args[, key])
Return the smallest item in an interable or the smallest of two or more arguments.
next(iterator[, default])
Retrieve the next item from the iterator by calling its __next__() method.
object
Return a new featureless object.
oct(x)
Convert an integer number to an octal string prefixed with “0o”.
open(file, mode=’r’, buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Open file and return a corresponding file object.
ord(c)
Given a string representing one Unicode character, return an integer representing the Unicode code point of that character.
pow(base, exp[, mod])
Return base to the power exp.
If mod is present, return base to the power exp, modulo mod.
print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Print objects to teh text stream file, separated by sept and followed by end, sept, end, file, and flush, if present
property(fget=None, fset=None, fdel=None, doc=None)
Return a property attribute.
range(stop)
range(start, stop[, step])
Rather than being a function, range is actually an immutable sequence type.
repr(object)
Return a string containing a printable representation of an object.
reversed(seq)
Return a reverse iterator.
round(number[,ndigits])
Return number rounded to ndigits precision after the decimal point.
set([iterable])
Return a new set object, optionally with elements taken from iterable.
setattr(object, name, value)
This is the counterpart of getattr() The function assions the value to the attribute.
slice(stop)
slice(start, stop[, step])
Return a slice object representing the set of indices specified by range(start, stop, step).
sorted(iterable, /, *, key=None, reverse=False)
Return a new sorted list from the items in iterable.
@staticmethod
Transform a method into a static method.
str(object=’’)
str(object=b’’, encoding=’utf-8’, errors=’strict’)
Return a str version of object.
sum(iterable, /, start=0)
Sums start and the items of an iterable from left to right and returns the total.
super([type[, object-or-type]])
Return a proxy object that delegates method calls to a parent or sibling class of type.
tuple([iterable])
Rather than being a function, tuple is actually an immutable sequence type.
type(object)
type(name, bases, dict, **kwds)
With one argument, return the type of an object.
vars([object])
Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.
zip(*iterables, strict=False)
Iterate over several iterables in parallel, producing tuples with an item from each one.
__import__(name, globals=None, locals=None, fromlist=(), level=0)
This function is invoked by the import statement.