Uploaded by Aung Kaung Khant [Anson Harris]

subprogram

advertisement
Subprogram
1
A subprogram is a self-contained module of code that
performs a specific task. It can be ‘called’ by the main
program when it is needed.
Function
2
A function is a subprogram that performs a specific task and
can be used at any point in the program.
High-level programming languages have a number of useful
built-in functions. You can also create your own or use
functions available in online libraries.
Built-in Functions
3
Built-in Functions functions that are provided in most
high-level programming languages to perform common
tasks
Example
bool() - Returns the boolean value of the specified object
int() - Returns an integer number
max() - Returns the largest item in an iterable
range() - Returns a sequence of numbers, starting from 0 and
increments by 1 (by default)
type() - Returns the type of an object
Object-oriented programming
4
OOP language an object-oriented programming language.
Instead of data structures and separate program
structures, both data and program elements are combined
into one structure called an object
Local Variable
5
Local variable a variable that is accessed only from within
the subprogram in which it is created
Global Variable
6
Global variable a variable that can be accessed from
anywhere in the program, including inside subprograms
Procedure
7
A subprogram containing a set of statements that are
executed when the procedure is called into use by a
command in the main program.
Unlike a function, a procedure does not return a value to
the main program.
Procedure example
8
Parameters
9
Parameters values that are passed into a subprogram when
it is called.
Example -
Scope
10
Scope the region of code within which a variable is visible
Download