Python: Built-In Functions Flashcards

1
Q

abs(x)

A

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.

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

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. This generates a string similar to that returned by repr() in Python 2.

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

class bool([x])

A

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

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

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

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 < 256. bytes is an immutable version of bytearray - it has the same non-mutating methods and the same indexing and slicing behavior.

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. Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method.

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.

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

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

A

Compile the source into a coe or AST object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

delattr(object, name)

A

This is a relative of setattr(). Deletes the named attribute, provided the object allows it.

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

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

A

Create a new dictionary.

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.

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 integer division.

18
Q

enumerate(iterable, start=0)

A

Return an enumerate object