Aliasing Flashcards
What is the global scope?
When a variable is defined outside any function, it’s scope is anywhere within the program. Variables and functions defined outside of a function are accessible inside of a functions
What is the local scope?
When u define a variable within a function, the scope lies only within the function. It’s value can’t be changed or accessed from outside the function. Python looks at local scope before global (refer to lec 9.1)
What is aliasing?
If an object being references is mutable (lists, sets, dictionaries), then a change made in the function is also reflected in the referenced
How can we avoid aliasing?
1) use list function
2) completely slice the list [ : ]
What are aliases?
When two variable names refer to the same object, they are aliases. When we modify one variable, we are modifying the object it refers to (also modifying second variable)