Python Built-In Functions Flashcards

1
Q

abs(x)

A

returns the absolute values of a number

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

all(iterable)

A

returns True if all elements of the iterable are true

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

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

ascii(object)

A

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.

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 prefixed with “0b”.

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

class bool([x])

A

Return a Boolean value, i.e. one of True or False

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

breakpoint(*args, **kws)

A

This function drops you into the debugger at the call site.

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

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

A

return a new array of bytes

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

class bytes([source[, encoding[, errors]]])

A

Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x

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

callable(object)

A

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

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

chr(i)

A

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().

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

@classmethod

A

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:

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

compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)

A

Compile the source into a code or AST object…

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

class complex([real[, imag]])

A

Return a complex number with the value real + imag*1j 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
15
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
16
Q

class dict(**kwarg)

class dict(mapping, **kwarg)

class dict(iterable, **kwarg)

A

Create a new dictionary. The dict object is the dictionary class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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
18
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 integer division.

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

enumerate(iterable, start=0)

A

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

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

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

A

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.

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

exec(object[, globals[, locals]])

A

This function supports dynamic execution of Python code. object must be either a string or a code object…

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

filter(function, iterable)

A

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.

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

class float([x])

A

Return a floating point number constructed from a number or string x.

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

format(value[, format_spec])

A

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

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

class frozenset([iterable])

A

Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class.

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

getattr(object, name[, default])

A

Return the value of the named attribute of object. name must be a string.

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

globals()

A

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).

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

hasattr(object, name)

A

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. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)

29
Q

hash(object)

A

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
Q

help([object])

A

Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console

31
Q

hex(x)

A

Convert an integer number to a lowercase hexadecimal string prefixed with “0x”. If x is not a Python int object, it has to define an __index__() method that returns an integer.

32
Q

id(object)

A

Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

33
Q

input([prompt])

A

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

34
Q

class int([x])

class int(x, base=10)

A

Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x defines __int__(), int(x) returns x.__int__(). If x defines __index__(), it returns x.__index__(). If x defines __trunc__(), it returns x.__trunc__().

35
Q

isinstance(object, classinfo)

A

Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns False.

36
Q

issubclass(class, classinfo)

A

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
Q

iter(object[, sentinel])

A

Return an iterator object…

38
Q

len(s)

A

Return the length (the 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).

39
Q

class list([iterable])

A

Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range.

40
Q

locals()

A

update and return a dictionary representing the current local symbol table.

41
Q

map(function, iterable, …)

A

Return an iterator that applies function to every item of iterable, yielding the results

42
Q

max(iterable, *[, key, default])

max(arg1, arg2, *args[, key])

A

Return the largest item in an iterable or the largest of two or more arguments…

43
Q

class memoryview(obj)

A

Return a “memory view” object created from the given argument. See Memory Views for more information

44
Q

min(iterable, *[, key, default])

min(arg1, arg2, *args[, key])

A

Return the smallest item in an iterable or the smallest of two or more arguments

45
Q

next(iterator[, default])

A

Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.

46
Q

class object

A

Return a new featureless object. object is a base for all classes.

47
Q

oct(x)

A

Convert an integer number to an octal string prefixed with “0o”.

48
Q

open(file, mode=’r’, buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

A

Open file and return a corresponding file object. If the file cannot be opened, an OSError is raised.

49
Q

ord(c)

A

Given a string representing one Unicode character, return an integer representing the Unicode code point of that character.

50
Q

pow(base, exp[, mod])

A

Return base to the power exp; if mod is present, return base to the power exp, modulo mod (computed more efficiently than pow(base, exp) % mod). The two-argument form pow(base, exp) is equivalent to using the power operator: base**exp.

51
Q

print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)

A

Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.

52
Q

class property(fget=None, fset=None, fdel=None, doc=None)

A

Return a property attribute.

53
Q

class range(stop)

class range(start, stop[, step])

A

Rather than being a function, range is actually an immutable sequence type

54
Q

repr(object)

A

Return a string containing a printable representation of an object.

55
Q

reversed(seq)

A

Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0).

56
Q

round(number[, ndigits])

A

Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input.

57
Q

class set([iterable])

A

Return a new set object, optionally with elements taken from iterable. set is a built-in class

58
Q

setattr(object, name, value)

A

This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value.

59
Q

class slice(stop)

class slice(start, stop[, step])

A
60
Q

sorted(iterable, *, key=None, reverse=False)

A

Return a new sorted list from the items in iterable.

61
Q

@staticmethod

A

Transform a method into a static method.

62
Q

class str(object=’’)

class str(object=b’’, encoding=’utf-8’, errors=’strict’)

A

Return a str version of object.

63
Q

sum(iterable, /, start=0)

A

Sums start and the items of an iterable from left to right and returns the total. The iterable’s items are normally numbers, and the start value is not allowed to be a string.

64
Q

super([type[, object-or-type]])

A

Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class.

65
Q

class tuple([iterable])

A

Rather than being a function, tuple is actually an immutable sequence type

66
Q

class type(object)

class type(name, bases, dict)

A

With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__.

67
Q

vars([object])

A

Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.

68
Q

zip(*iterables)

A

Make an iterator that aggregates elements from each of the iterables.

69
Q

__import__(name, globals=None, locals=None, fromlist=(), level=0)

A

This function is invoked by the import statement…