Textbook Notes (270,000)
CA (160,000)
U of C (1,000)
CPSC (7)
Chapter 5, 6

CPSC 231 Chapter Notes - Chapter 5, 6: Local Variable, Global Variable

Computer Science
Course Code
CPSC 231
Rob Kremer
5, 6

This preview shows half of the first page. to view the full 2 pages of the document.
It is a named sequence of statements that belong together.
[ def name(parameters/arguments):
statements ]
There are built-in functions, such as abs, min, max.
- You should not have any statements in a function after the
return statement. Once the function gets to the return statement
it will immediately stop executing the function.
Variables and Parameters are Local:
You cannot call a variable or a parameter which is inside a
function because they are local to that speci*c function, the
program won’t understand those.
Local variable shadows the global one, if it’s found, global
variable will not be used in the function.
The accumulator Pattern:
Total = 0, then for total + 1, total = 1, total = 2, total = 3 …
Functions can call other functions, a parameter can be used twice
when calling the other one.
Create a main function to order other functions and invoke it with
main() [without colons]
A = [1, 4, 5], for a in A: func(w/e, a), it will call the elements in
You're Reading a Preview

Unlock to view full version