Functions Flashcards

Chapter 4 (44 cards)

1
Q

Returns the absolute value of a number

A

X=abs(number)

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

Returns True if all items in an iterable object are true

A

x=all(iterable)

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

Returns True if any item in an iterable object is true

A

x=any(iterable)

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

Returns a readable version of an object. Replaces none-ascii characters with escape character

A

x=ascii(object)

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

Returns the binary version of a number

A

X=bin(integer)

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

Returns the boolean value of the specified object

A

X=bool(object)

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

Returns True if the specified object is callable, otherwise False

A

X=callable(object)

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

Returns the specified source as an object, ready to be executed

A

X=compile(source, filename, mode, flag, dont_inherit, optimize)

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

Returns a complex number

A

X=complex(real,imaginary)

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

Deletes the specified attribute (property or method) from the specified object

A

delattr(object, attribute)

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

Returns a dictionary (Array)

A

X=dict(key=value,…)

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

Returns the quotient and the remainder when argument1 is divided by argument2

A

X=divmod(dividend, divisor)

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

Takes a collection (e.g. a tuple) and returns it as an enumerate object

A

X=enumerate(iterable, start)

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

Use a filter function to exclude items in an iterable object

A

X=filter(function, iterable)

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

Returns a floating point number

A

X=float(value)

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

Formats a specified value

A

X=format(value, format)

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

Returns the value of the specified attribute (property or method)

A

X=getattr(object, attribute, default)

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

Returns True if the specified object has the specified attribute (property/method)

A

X=hasattr(object, attribute)

19
Q

Returns the hash value of a specified object

20
Q

Allowing user input

A

X=input(prompt)

21
Q

Returns an integer number

A

X=int(value, base)

22
Q

Returns True if a specified object is an instance of a specified object

A

X=isinstance(object, type)

23
Q

Returns True if a specified class is a subclass of a specified object

A

X=issubclass(object, subclass)

24
Q

Returns the length of an object

A

X=len(object)

25
Returns a list
X=list(iterable)
26
Returns the largest item in an iterable
X=max(n1, n2, n3, ...) Or: X=max(iterable)
27
Returns the smallest item in an iterable
X=min(n1, n2, n3, ...) Or: X=min(iterable)
28
Returns the next item in an iterable
X=next(iterable, default)
29
Returns a new object
X = object()
30
Opens a file and returns a file object
open(file, mode) Modes: "r" - Read - Default value. Opens a file for reading, error if the file does not exist "a" - Append - Opens a file for appending, creates the file if it does not exist "w" - Write - Opens a file for writing, creates the file if it does not exist "x" - Create - Creates the specified file, returns an error if the file exist
31
Returns the value of x to the power of y
pow(x, y, z)
32
Prints to the standard output device
print(object(s))
33
Returns a sequence of numbers, starting from 0 and increments by 1 (by default)
X=range(start, stop, step)
34
Returns a reversed iterator
X=reversed(sequence)
35
Rounds a number
X=round(number, digits)
36
Returns a new set object
X=set(iterable)
37
Sets an attribute (property/method) of an object
setattr(object, attribute, value)
38
Returns a slice object
X=slice(start, end, step)
39
Returns a sorted list Note: You cannot sort a list that contains BOTH string values AND numeric values.
sorted(iterable, key=key, reverse=reverse)
40
Returns a string objec
X=str(object)
41
Sums the items of an iterator
X=sum(iterable, start)
42
Returns a tuple Note: You cannot change or remove items in a tuple.
X=tuple(iterable)
43
Returns the type of an object
X=type(object, bases, dict)
44
Returns an iterator, from two or more iterators
Y=zip(iterator1, iterator2, iterator3 ...)