Functions Flashcards
How much do you need to indent a code block by for a user-defined function?
4 spaces or a tab
What are parameters?
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
What is the name of output from a function?
“Return value”
How do you define a function?
Def function_name(param1, …, paramn)
What is a docstring?
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 does a docstring differ from a #comment
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 do you access the docstring
help() or doc
What is the typical name of a function that begins a program?
def main():
What is the purpose of the name function?
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
What is the purpose of the main function?
the main function is typically what the beginning of a module to begin all other modules
in a function when a condition is true should is be in the body of the if elif or else?
if
If a condition is not met what decision-based condition can be what to do?
else:
what is the second true function for decision-based conditions?
elif
Can you use more than one elif in a block of code?
yes
Can you have multiple if conditionals?
yes - they will be tested separately