Chapter 4: Functions Flashcards
A general process for solving a category of problems.
algorithm
A value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function.
argument
The sequence of statements inside a function definition.
body
Using an expression as part of a larger expression, or a statement as part of a larger statement.
composition
Pertaining to a program that does the same thing each time it runs, given the same inputs.
deterministic
The syntax for calling a function in another module by specifying the module name followed by a period and the function name.
dot notation
The order in which statements are executed during a program run.
flow of execution
A function that returns a value.
Value needs to be printed or saved to variable in a script. Displays in interactive mode.
fruitful function
A named sequence of statements that performs some useful operation. May or may not take arguments and may or may not produce a result.
function
A statement that executes a function. It consists of the function name followed by an argument list.
function call
A statement that creates a new function, specifying its name, parameters, and the statements it executes.
function definition
A value created by a function definition. The name of the function is a variable that refers to it.
function object
The first line of a function definition.
header
A statement that reads a module file and creates a module object.
import statement
A value created by an import statement that provides access to the data and code defined in a module.
module object
A name used inside a function to refer to the value passed as an argument.
parameter
Pertaining to a sequence of numbers that appear to be random, but are generated by a deterministic program.
pseudorandom
The result of a function. If a function call is used as an expression, it’s the value of the expression.
Saved into a variable for use outside the function
return value
A function that does not return a value.
void function
built-in function that returns smallest value
(strings: a < z)
min function
min()
built-in function that returns largest value
(strings: z > a)
max function
max()
built-in function that returns number of items in object
eg. sequence (string,list) or collection
length function
len()
Sequence types (7)
strings
unicode strings
lists
tuples
bytearrays
buffers
xrange objects
ordered sequence of items that is referred to by a single name, such that any given item within it can be specified by
using that name along with an index value that selects that item
uses [] brackets
list
function that generates random value between 0.0 and 1.0 (excluded)
random function
random.random()
function that generates random value between low and high parameters (included)
randint function
random.randint(1,10)
function that selects an element from a given sequence at random
(eg. string or list)
choice function
random.choice(string/list)
end function in interactive mode
empty line
…
method to embed single quotes within string
triple quotes
“"”I’m a lumberjack and I’m ok”””
take a complex process and break it down into a set of simpler functions.
aka functions calling other functions
functional decomposition