Lab 7: Part 1. Memory Diagrams
Why Memory Diagrams?
Aliasing is when the same memory location can be acccessed using different variable names. In other words, aliasing occurs when two different variables point to the same location in memory. The best way to see and understand this is by drawimg memory diagrams.
Prefer a digital version of these tasks? Click here and make a copy.
Below is a snippet of code. Write the output that is generated by the print statements.
a = [2, 4, 6] b = [1, 3, 5] b = a * a a.insert(1,'water') print('---- 1st print ----') print(a) print(b) a = b print('---- 2nd print ----') print(a) print(b) b.pop() b.append('blue') print('---- 3rd print ----') print(a) print(b)
Below is another snippet of code. Write the output that is generated by the print statements. Draw a memory diagram to visualize the code.
x = [80, 75, 50] y = x z = [x, y] x = 100 y.append('hi') z.insert(1, x + y) z.pop(1) print(x) print(y) print(z)
Table of Contents
- Lab 7 Home
- Part 1: Memory Diagrams
- Part 2: Nested Loop Warm up
- Part 3: Nested Loops
- Knowledge Check