Ch.8 Functions Flashcards

1
Q

What is a function?

A

A named block of code that is designed to do one specific job, very very well.

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

Where do the parameters and arguments go in your code?

A
def function_name(parameter)
      ................

function_name(argument)

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

What is the argument?

A

It is a piece of information that’s passed form a function call to a function.

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

How do you use a default value?

A

def funciton_name( parameter_1, parameter_2 = default value)

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

What does a return statement do?

A

It takes a value from inside a function and sends it back to the line that called the function.

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

Where do you place the parameter if the argument if it is optional?

A

You place it last, for example: def function_name(p_1, p_2, optional_p)

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

How do you modify a list?

A

By making changes to the list inside the function’s body, because this change is permanent.

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

How do you prevent a function from modifying a list?

A

By sending a copy of a list to a function, like this: function_name(list_name[:])
because the slice notation [:] makes a copy of the list.

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

How do you pass an arbitrary number of arguments?

A
by using an asterisk:
def function_name(*parameters)

the asterisk tells python to make an empty tuple and pack whatever values it receives into the tuple.

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

How do you mix positional arguments and arbitrary arguments?

A

def function_name(positional, *arbitrary)

the arbitrary one goes last

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

How do you use arbitrary keyword arguments?

A

With two asterisks before the parameter.

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