Built-in Funcitons Flashcards

Retain and understand how to use all of pythons built-in functions. (42 cards)

1
Q

abs(x)

A

Return the absolute value of a number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

all(iterable)

A

Return True if all elements of the iterable are true (or if the iterable is empty).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

any(iterable)

A

Return True if any element of the iterable is true. If the iterable is empty, return False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

basestring()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

bin(x)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

bool([x])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

bytearray([source[, encoding[, errors]]])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

callable(object)

A

Return True if the object argument appears callable, False if not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

chr(i)

A

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string ‘a’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

classmethod(function)

A
Return a class method for function.
A class method receives the class as implicit first argument, just like an instance method receives the instance.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

cmp(x, y)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

compile(source, filename, mode[, flags[, dont_inherit]])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

complex([real[, imag]])

A

Create a complex number with the value real + imag*j or convert a string or number to a complex number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

delattr(object, name)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

dict(**kwarg)
dict(mapping, **kwarg)
dict(iterable, **kwarg)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

dir([object])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

divmod(a, b)

A

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division.

18
Q

enumerate(sequence, start=0)

A

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration.

19
Q

eval(expression[, globals[, locals]])

A

> > > x = 1
print eval(‘x+1’)
2

20
Q

execfile(filename[, globals[, locals]])

A

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

21
Q

file(name[, mode[, buffering]])

A

Constructor function for the file type, described further in section File Objects.

22
Q

filter(function, iterable)

A

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.

23
Q

float([x])

A

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.

24
Q

format(value[, format_spec])

A

Convert a value to a “formatted” representation, as controlled by format_spec.

25
frozenset([iterable])
Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class.
26
getattr(object, name[, default])
Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar.
27
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).
28
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, False if not.
29
hash(object)
Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup.
30
help([object])
Invoke the built-in help system. (This function is intended for interactive use.)
31
hex(x)
Convert an integer number (of any size) to a hexadecimal string. The result is a valid Python expression.
32
id(object)
Return the “identity” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime.
33
input([prompt])
Equivalent to eval(raw_input(prompt)). This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised.
34
int(x=0) | int(x, base=10)
Convert a number or string x to an integer, or return 0 if no arguments are given. If x is a number, it can be a plain integer, a long integer, or a floating point number. If x is floating point, the conversion truncates towards zero. If the argument is outside the integer range, the function returns a long object instead.
35
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. Also return true if classinfo is a type object (new-style class) and object is an object of that type or of a (direct, indirect or virtual) subclass thereof.
36
issubclass(class, classinfo)
Return true if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked.
37
iter(o[, sentinel])
Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, o must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0).
38
len(s)
Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).
39
list([iterable])
Return a list whose items are the same and in the same order as iterable‘s items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a list, a copy is made and returned, similar to iterable[:]. For instance, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, returns a new empty list, [].
40
locals()
Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks.
41
long(x=0) | long(x, base=10)
Convert a string or number to a long integer. If the argument is a string, it must contain a possibly signed number of arbitrary size, possibly embedded in whitespace. The base argument is interpreted in the same way as for int(), and may only be given when x is a string.
42
map(function, iterable, ...)
Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel.