What is isinstance() and what are its arguments?
isinstance(object, classinfo, /)
Return True if the object argument is an instance of the classinfo argument, or a subclass thereof.
What is next() and what are its arguments?
next(iterator, /)
next(iterator, default, /)
Retrieve the next item from the iterator by calling its __next__() method.
What is eval() and what are its arguments?
eval(source, /, globals=None, locals=None)¶
eval() is a function that parses the source and evaluates it as a Python expression using the globals and locals mappings as global and local namespace.
What is print() and what are its arguments?
print(*objects, sep=' ', end='\n', file=None, flush=False)
Prints objects to the text stream file, separated by sep and followed by end.
What is range() and what are its arguments?
class range(stop, /)
class range(start, stop, step=1, /)
range is an immutable sequence type, not a function.
What is getattr() and what are its arguments?
getattr(object, name, /)
getattr(object, name, default, /)
Return the value of the named attribute of object. name must be a string.
Ex.
getattr(x, 'foobar') is equivalent to x.foobar.
What is map() and what are its arguments?
map(function, iterable, /, *iterables, strict=False)
map() is a function that returns an iterator that applies function to every item of iterable, yielding the results.
Ex:
words = ['hello', 'world', 'python']
upper = list(map(str.upper, words))
What is breakpoint() and what are its arguments?
breakpoint(*args, **kws)
This function drops you into the debugger at the call site. By default, it drops you into pdb by calling pdb.set_trace() expecting no arguments. In this case, it is a convenience function so you don't have to explicitly import pdb. But you can also use it to drop into a different debugger.
What is repr() and what are its arguments?
repr(object, )
Returns a string containing a printable representation of an object.
What is bytearray() and what are its arguments?
class bytearray(source=b'') class bytearray(source, encoding, errors='strict')
Returns a new array of bytes. bytearray is a mutable sequence of integers in the range 0 <= x < 256.
What is setattr() and what are its arguments?
setattr(object, name, value, /)
Sets the object's name field to value.
For example, setattr(x, 'foobar', 123) is equivalet to x.foobar = 123.
What is enumerate() and what are its argument?
enumerate(iterable, start=0)
Equivalent to
def enumerate(iterable, start=0):
n = start
for elem in iterable:
yield n, elem
n += 1
Ex:
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
What is open() and what are its arguments?
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
open() is a function that opens a file and returns a corresponding file object. file is a path-like object.
What is format() and what are its arguments?
format(value, format_spec='', /)
format() is a function that converts a value to a "formatted" representation.
What is bytes() and what are its arguments?
class bytes(source=b'')
class bytes(source, encoding, errors='strict')
bytes is an immutable sequence of integers in the range 0 <= x < 256.
What is len() and what are its arguments?
len() is a function that returns the length (number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).
What is zip() and what are its arguments?
zip(*iterables, strict=False)
Iterate over several iterables in parallel, producing tuples with an item from each one.
for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']):
print(item)
(1, 'sugar')
(2, 'spice')
(3, 'everything nice')
What is help() and what are its arguments?
help()
help(request)
help() is a function that invokes the built-in help system (this function is intended for interactive use).
What is input() and what are its arguments?
input()
input(prompt, /)
input() is a function that reads a line from input, converts it to a string (stripping a trailing newline), and returns that.What is hex() and what are its arguments?
hex(integer, /)
hex() is a function that converts an integer number to a lowercase hexadecimal string prefixed with "0x".
hex(255)
'0xff'
hex(-42)
'-0x2a'
If you want to convert an integer number to an uppercase or lower hexadecimal string with prefix or not, you can use either of the following ways:
'%#x' % 255, '%x' % 255, '%X' % 255
('0xff', 'ff', 'FF')
format(255, '#x'), format(255, 'x'), format(255, 'X')
('0xff', 'ff', 'FF')
f'{255:#x}', f'{255:x}', f'{255:X}'
('0xff', 'ff', 'FF')
What is hasattr() and what are its arguments?
hasattr(object, name, /)
The arguments are an object and a string. The result is True if the string is the name of one of the object's attributes.
What is filter() and what are its arguments?
filter(function, iterable, /)
Construct an iterator from those elements of iterable for which function is true.
Ex:
huge_numbers = range(1000000)
evens = filter(lambda x: x % 2 == 0, huge_numbers)
What is exec() and what are its arguments?
exec(source, /, globals=None, locals=None, *, closure=None)¶
This function supports dynamic execution of Python code. source must be either a string or a code object.
What is ascii() and what are its arguments?
ascii(object, /)
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters.
What is type() and what are its arguments?
class type(object, /)
class type(name, bases, dict, /, **kwargs)
Return the type of an object. This is generally the same as object.__class__.
It's better to use isinstance() because that takes subclasses into account.