CS 220 - Function Scope Practice

Practice 1

Practice 2

Practice 3

Lesson 1: functions don't execute unless they're called

Lesson 2: variables created in a function die after function returns

Lesson 3: variables start fresh every time a function is called again

Lesson 4: you can't see the variables of other function invocations, even those that call you

Lesson 5: you can generally just use global variables inside a function

Lesson 6: if you do an assignment to a variable in a function, Python assumes you want it local

Lesson 7: assignment to a variable should be before its use in a function, even if there's a a global variable with the same name

Lesson 8: use a global declaration to prevent Python from creating a local variable when you want a global variable

Lesson 9: in Python, arguments are "passed by value", meaning reassignments to a parameter don't change the argument outside

Lesson 10: it's irrelevant whether the argument (outside) and parameter (inside) have the same variable name