Functions Flashcards

1
Q

How much do you need to indent a code block by for a user-defined function?

A

4 spaces or a tab

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

What are parameters?

A

A parameter is the variable listed inside the parentheses in the function definition. When you call the function you pass arguments to satisfy the parameters

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

What is the name of output from a function?

A

“Return value”

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

How do you define a function?

A

Def function_name(param1, …, paramn)

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

What is a docstring?

A

Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code.

A docstring is for someone who is using your function and wants to know what it does at a high level

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

How does a docstring differ from a #comment

A

Docstrings differ from comments as a docstring is for the user to understand WHAT the function does

Comments are used for the programmer who is using the code to understand HOW the code works.

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

How do you access the docstring

A

help() or doc

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

What is the typical name of a function that begins a program?

A

def main():

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

What is the purpose of the name function?

A

The name function is used as the title as such to a script. If you are running the module within the program it is usually set to main. If it is outside of the module it will be the name of the script file.

__name__ is one such special variable. If the source file is executed as the main program, the interpreter sets the __name__ variable to have a value “__main__”. If this file is being imported from another module, __name__ will be set to the module’s name

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

What is the purpose of the main function?

A

the main function is typically what the beginning of a module to begin all other modules

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

in a function when a condition is true should is be in the body of the if elif or else?

A

if

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

If a condition is not met what decision-based condition can be what to do?

A

else:

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

what is the second true function for decision-based conditions?

A

elif

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

Can you use more than one elif in a block of code?

A

yes

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

Can you have multiple if conditionals?

A

yes - they will be tested separately

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

print just shows the human user a string representing what is going on inside the computer. The computer cannot make use of that printing. return is how a function gives back a value. This value is often unseen by the human user, but it can be used by the computer in further functions

A