week 9 functions with lists Flashcards
defining lists
can be hardcoded, list function, or from a file
mutable types in functions
list, dictionary, and set that are passed into function are also altered in the workspace
index method
allows you to search ordered object for certain value and returns the index
expense
the number of comparisons needed to find something (in reference to methods)
ordering/sorting data
increases efficiency because you know where stuff is and can select certain chunks to search for something
binary search
reducing search items by sorting data
scope
part of a program that variable/function exists
local variables
variables defined in functions, the scope is within the function
global variable
created outside function, scope is from defining statement until the end of the file
global statement
used to change a global value and create a global value inside a function (use keyword global, then state function name)
do modifications to mutable types within a function need a global statement?
no
function scope
from function definition until the end of the file
namespace
maps names to objects
locals()
prints all local variables
globals()
prints all global variables
3 nested scopes
built-in scope, local scope, global scope
built-in scope
contains built-in python names, like int, str, list, etc