Python Functions Flashcards
Learn about functions in Python
Function
A named sequence of statements that performs a computation.
Function call
Evoking a function by its name.
*This is like a detour in the flow of execution. Instead of going to the next statement, the flow jumps to the body of the function, runs the statements there, and then returns to where it left off.
Argument
The expression in parentheses after the name of a function.
*A function ‘takes’ an argument and ‘returns’ a result.
Return value
The returned result of a function.
When int() is used to convert floating-point values into integers, does it round off or omit the fraction?
int() omits the fraction of a floating-point value when converting it to an integer.
Module
A file that contains a collection of related functions.
Import statement
A statement used to import a module in order to use the functions therein.
*These statements create ‘module objects’
How do you access one of the functions defined in a module object?
Specify the name of the module and the name of the function, separated by a dot (dot notation)
math. pi
math. sin()
math. log10()
math. sqrt()
Function definition
Specifies the name of a new function and the sequence of statements that run when the function is called.
def NewFunction(): print("I'm a good boy")
*Function definitions do not alter the flow of a program.
def
The keyword that indicates that this is a function definition.
- The first character in the name of a function cannot be a number, and the name cannot be a keyword.
- A function does not have to take any arguments.
Header
The first line of a function definition. It must end with a colon.
Body
The rest of a function definition following the header. The body must be indented.
Function object
Created when defining a function, it has type “function”.
Can you use a function inside another function?
Yes, if it has already been defined.
Statements inside a function are only run when the function is called. T/F?
True