13 terms

Python Functions: Local vs. Global variables

STUDY
PLAY

Terms in this set (...)

A variable declared in the main code is a ______ variable.
Global
A variable declared in a function is a ________ variable.
local
A parameter is a ________ variable.
local
Global and local variables differ in their _______
scope
Code a statement that, depending on whether it occurs within a function or in the main code, determines whether purchaseTotal has global or local scope.
purchaseTotal = 3
Code something called useless that does nothing but create valueless, which has local scope.
def useless():
valueless = 0
Code a statement that assigns the value returned by a function to a global variable.
age = checkAge()
Code a function without parameters that does nothing but create two local variables.
def makeVars():
firstVar = 2
secondVar = 9
Code a statement that passes the value of a local variable to a global variable in the main code.
return total
Code a statement that passes the values of two global variables to a function and anticipates that the function will return a value to be assigned to a new global variable. The global variable hasn't been declared beforehand.
globalVar = processNums(num1, num2)
Code a function without parameters that creates two local variables and does nothing with them. Then it (unwisely) assigns the number 10 to a global variable that you've made up without a return statement.
def reckless():
safeVariable1 = 2
safeVariable2 = 3
global unsafeVariable
unsafeVariable =10
Code the first line of a function that implicitly declares two local variables.
def doSomething(param1, param2):
The only place where a local variable has a value is within the ________ where it is declared.
function