Computer Science · Ch 7 — Functions
Summary
Summary
- Functions are used in programming to achieve modularity and reusability.
- A function is a named group of instructions that executes when the function is invoked (called) by its name. Functions written by the programmer are user defined functions.
- The Python interpreter has many functions permanently built into it — the frequently used built-in functions such as
input(),int()andprint(). - An argument is a value passed to a function during the function call; it is received in a parameter defined in the function header.
- Python allows a parameter to be given a default value, used when the call supplies no corresponding argument.
- A function sends value(s) back to its caller using the
returnstatement. - Multiple values are returned from a Python function packed in a tuple.
- Flow of execution is the order in which the statements of a program are executed; a function's body runs only when the function is called, and control returns to the point of the call afterwards.
- The scope of a variable is the part of the program where the variable is accessible.
- A global variable is defined outside any function or block and can be accessed anywhere in the program.
- A local variable is defined inside a function or block, is accessible only there, and exists only while the function executes.
- The Python standard library is an extensive collection of functions and modules that speeds up program development. …