Python: Built-In Functions Flashcards
abs(x)
Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, it’s magnitude is returned.
all(iterable)
Return “True” if all elements of the iterable are true (or if the iterable is empty).
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. This generates a string similar to that returned by repr() in Python 2.
bin(x)
Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a python “int” object, it has to define an __index__() method that returns an integer.
class bool([x])
Return a Boolean value, i.e. on of “True” or “False.” x is converted using the standard truth testing procedure. If x is false or omitted, this returns “False”; otherwise it returns “True.” The bool class is a subclass of int. It cannot be subclassed further. Its only instances are “False” and “True.”
breakpoint(*args, **kws)
This function drops you into the debugger at the call site. Specifically, it calls “sys.breakpointhook(),” passing “args” and “kws” straight through. By default, “sys.breakpointhook()” calls pdb.set_trace() expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly import pdb or type as much code to enter the debugger. However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice.
class bytearray([source[, encoding[, errors]]])
Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <== x < 256. It has most of the usual methods of mutable sequences, as well as most methods that the bytes type has.
class bytes([source[, encoding[, errors]]])
Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256. bytes is an immutable version of bytearray - it has the same non-mutating methods and the same indexing and slicing behavior.
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. Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method.
chr(i)
Return the string representing a character whose Unicode code point is the integer i.
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
Compile the source into a coe 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(). Deletes the named attribute, provided the object allows it.
class dict(**kwarg), dict(mapping, **kwarg), dict(iterable, **kwarg)
Create a new dictionary.