Functions Flashcards

Chapter 4

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

A

Hash()

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
Q

Returns a list

A

X=list(iterable)

26
Q

Returns the largest item in an iterable

A

X=max(n1, n2, n3, …)

Or:

X=max(iterable)

27
Q

Returns the smallest item in an iterable

A

X=min(n1, n2, n3, …)

Or:

X=min(iterable)

28
Q

Returns the next item in an iterable

A

X=next(iterable, default)

29
Q

Returns a new object

A

X = object()

30
Q

Opens a file and returns a file object

A

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
Q

Returns the value of x to the power of y

A

pow(x, y, z)

32
Q

Prints to the standard output device

A

print(object(s))

33
Q

Returns a sequence of numbers, starting from 0 and increments by 1 (by default)

A

X=range(start, stop, step)

34
Q

Returns a reversed iterator

A

X=reversed(sequence)

35
Q

Rounds a number

A

X=round(number, digits)

36
Q

Returns a new set object

A

X=set(iterable)

37
Q

Sets an attribute (property/method) of an object

A

setattr(object, attribute, value)

38
Q

Returns a slice object

A

X=slice(start, end, step)

39
Q

Returns a sorted list

Note: You cannot sort a list that contains BOTH string values AND numeric values.

A

sorted(iterable, key=key, reverse=reverse)

40
Q

Returns a string objec

A

X=str(object)

41
Q

Sums the items of an iterator

A

X=sum(iterable, start)

42
Q

Returns a tuple

Note: You cannot change or remove items in a tuple.

A

X=tuple(iterable)

43
Q

Returns the type of an object

A

X=type(object, bases, dict)

44
Q

Returns an iterator, from two or more iterators

A

Y=zip(iterator1, iterator2, iterator3 …)