Aliasing Flashcards

1
Q

What is the global scope?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the local scope?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is aliasing?

A

If an object being references is mutable (lists, sets, dictionaries), then a change made in the function is also reflected in the referenced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we avoid aliasing?

A

1) use list function

2) completely slice the list [ : ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are aliases?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly