Python Built-In Functions Flashcards
abs(x)
returns the absolute values of a number
all(iterable)
returns True if all elements of the iterable are true
any(iterable)
return True if any element of the iterable is true
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”.
class bool([x])
Return a Boolean value, i.e. one of True or False
breakpoint(*args, **kws)
This function drops you into the debugger at the call site.
class bytearray([source[, encoding[, errors]]])
return a new array of bytes
class bytes([source[, encoding[, errors]]])
Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x
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
chr(i)
Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string ‘a’, while chr(8364) returns the string ‘€’. This is the inverse of ord().
@classmethod
Transform a method into a class method.
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
Compile the source into a code or AST object…
class 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)
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.
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Create a new dictionary. The dict object is the dictionary class
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. 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.
exec(object[, globals[, locals]])
This function supports dynamic execution of Python code. object must be either a string or a code object…
filter(function, iterable)
Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator.
class 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.
class frozenset([iterable])
Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class.
getattr(object, name[, default])
Return the value of the named attribute of object. name must be a string.
globals()
Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).