Built-in Funcitons Flashcards
Retain and understand how to use all of pythons built-in functions. (42 cards)
abs(x)
Return the absolute value of a number.
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.
basestring()
This abstract type is the superclass for str and unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str or unicode.
bin(x)
Convert an integer number to a binary string. 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.
bool([x])
Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
bytearray([source[, encoding[, errors]]])
Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 < 256.
It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the str type has, see String Methods.
callable(object)
Return True if the object argument appears callable, False if not.
chr(i)
Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string ‘a’.
classmethod(function)
Return a class method for function. A class method receives the class as implicit first argument, just like an instance method receives the instance.
cmp(x, y)
Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y.
compile(source, filename, mode[, flags[, dont_inherit]])
Compile the source into a code or AST object. Code objects can be executed by an exec statement or evaluated by a call to eval(). source can either be a Unicode string, a Latin-1 encoded string or an AST object.
complex([real[, imag]])
Create a complex number with the value real + imag*j 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.
dict(**kwarg)
dict(mapping, **kwarg)
dict(iterable, **kwarg)
Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types — dict for documentation about this class.
For other containers see the built-in list, set, and tuple classes, as well as the collections module.
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 long division.
enumerate(sequence, start=0)
Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration.
eval(expression[, globals[, locals]])
> > > x = 1
print eval(‘x+1’)
2
execfile(filename[, globals[, locals]])
The file is parsed and evaluated as a sequence of Python statements (similarly to a module) using the globals and locals dictionaries as global and local namespace
file(name[, mode[, buffering]])
Constructor function for the file type, described further in section File Objects.
filter(function, iterable)
Construct a list from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If iterable is a string or a tuple, the result also has that type; otherwise it is always a list.
float([x])
Convert a string or a number to floating point. If the argument is a string, it must contain a possibly signed decimal or floating point number, possibly embedded in whitespace.
format(value[, format_spec])
Convert a value to a “formatted” representation, as controlled by format_spec.