Software DD (Implementation: Parameter Passing) Flashcards
Formal Parameters
Formal parameters are the identifiers used to stand for a value that will be passed when a subprogram/method is called:
def CelsiusToFahr(celsius):
From RGC Aberdeen website
Actual Parameters
Actual parameters are the actual values that is passed into the method/subroutine/function.
Fahrenheit = CelsiusToFahr(78)
or
Fahrenheit = CelsiusToFahr(inputtemp)
From RGC Aberdeen website
Global Variable
A global variable means it is accessible in EVERY sub-routine of the entire program.
* Python assumes each variable is local if is specified inside a subroutine.
* Python assumes each variable is global if it is specified outside of a subroutine.
This is not a good idea….
* This means EVERY subroutine can change them accidentally.
* The way to counter this is to use local variables.
From RGC Aberdeen website
Local Variable
Local variables only exist in the subroutine in which they are declared. This is known as the scope of a variable.
For example if there was a variable called counter that was used to control loops and your program had numerous loops then that variables value would change all the time.
From RGC Aberdeen website
Advantages of Local Variables
- Aids modularity
Allows subroutines to be used with their own variables - More efficient in terms of memory
Local variables are disposed of when the subroutine finishes - Removes naming clashes with other local variables in other subroutines
E.g loop counter variables
From RGC Aberdeen website
Functions and Subroutines
A function returns a value(s) which can be assigned to a variable. Where as a subroutine may not pass out any values.
From RGC Aberdeen website