04 Functions Flashcards

(9 cards)

1
Q

How do you declare a function

A

def, followed by function name , followed by list of arguments to be passed to the function, ends with colon

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

docstring

A

documentation string that describes in words what the problem does

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

function

A

a block of code that can be reused multiple times with different input data

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

How does writing more code increase the likelihood of errors?

A

More code means some sections are used less frequently, making errors harder to detect and more likely

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

What is the order in which arguments should be passed into a function

A

Order in which function arguments are listed

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

Why is it useful to have a default argument values that can override functions

A

Saves the programmer effort, less code to write

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

Scope

A

the variables declared inside the function are not visible outside the function
do not have to worry about variables affecting other parts of program

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

Recursion

A

Function makes called to itself

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

Named arguments

A

Used when a function has numerous arguments
Case order does not matter
Enhances program readability + reduces errors

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