Week 6 - Functions Flashcards
What is a function?
Named sequence of statements that belong together.
What is a parameter?
Also known as Formal Parameter.
Must be a variable.
Specify what, if any, info you have to provide in order to use the function.
What is an argument?
Also known as Actual parameters.
It is the information that the function needs to work.
They are passed by the user.
What is the return statement?
Used at the end of a function’s body
Is followed by an expression which is evaluated
Terminates the function with a value
What are fruitful functions?
Functions that return a value.
Use the return statement
What are non-fruitful functions?
A function that does not return a value.
Does not use the return statement
What is an abstraction?
Refers to naming a concept.
Functions are abstractions
What is a concrete abstraction?
All details are visable
What is an abstract abstraction?
No details are visible, just a name
What is Generalisation?
It is when you add parameters to a function, which makes the function more general.
What are specific generalisations?
They do just one task.
What are general generalisations?
Can do many tasks
What are comments and how do you create?
Comments are notes for a programmer and can be thought of as documentation.
They can start with a # symbol or be enclosed in triple quotes ‘'’….’’’
What is a docstring and how do you create?
Docstrings clearly describe what the function does, so someone else can understand.
Can be known as documentation.
The are enclosed in triple quotes ‘'’…’’’ and are generally listed in the line following the function name.
What is unit testing and how do you use it?
A unit test will test what is returned in a function.
Import test needs to be completed.
The user needs to know the outcome.
test.testEqual(function_name(argument), result).