Python for GCSE

6: Sub programs

Revision tools
You can print this page for a quick reference guide or you can use the tools below to create printable test sheets
6.1: understand the benefits of using subprograms
Sub programs
KeywordDefinition
calltell the program to actually execute (run) the subprogram
definetells the program how to execute (run) the subprogram
functiona section of code with a name that can be re-used. It always returns a value
procedurea section of code with a name that can be re-used. It can't return a value.
returnsend data back to the part of the program which called the subprogram
subprograma section of code with a name that can be re-used (e.g. function or procedure)
6.2: be able to write code that uses user-written and pre-existing (built- in, library) subprograms
Sub programs
KeywordDefinition
library sub programa procedure or function that can be used by importing a module (e.g. random.randint or time.sleep)
predefined sub programa procedure or function that is built into the programming language (e.g. max, min, input or print)
user defined subprograma procedure or function that the user has written themselves
6.3: understand the concept of passing data into and out of subprograms (procedures, functions)
Sub programs
KeywordDefinition
callmake a procedure or function actually run
functiontype of subprogram which is a section of code with a name that can be re-used. Always returns a value
parametera value that is passed to a subprogram by the part of the code which calls the procedure or function
proceduretype of subprogram which is a section of code with a name that can be re-used. Doesn't return a value.
returngo back from a procedure or function to the part of the program that called it
return valuedata that is passed back from a procedure or function to the part of the program that called it
6.4: understand the need for, and how to use, global and local variables when implementing subprograms
Sub programs
KeywordDefinition
global variablea variable which can be accessed from anywhere in a program
local variablea variable which can only be read / written within a particular part of a program
scopethe part of a program where a variable can be accessed.
variablememory storage location with a name that can store an individual value. The value can change when the program runs.