Want to create interactive content? It’s easy in Genially!

Get started free

Memory address

dlhtech

Created on December 8, 2023

Start designing with a free template

Discover more than 1500 professional designs like these:

Transcript

Variable Names

Memory address

Step 0

Initially, there are no variables and no objects

a = [1, “apple”] b = [2, 3] a.append(b) print(a[2][0], b[0]) b[0] = “banana” print(a[2][0], b[0]) b = 0

Objects in Memory
Variable Names

Memory address

Step 1

We created a variable named a which references a new list We also create an integer and a string The list contains references to the integer and string We can access the integer and string by providing an index to the list For example, a[0] accesses the value 1

a = [1, “apple”] b = [2, 3] a.append(b) print(a[2][0], b[0]) b[0] = “banana” print(a[2][0], b[0]) b = 0

list

[0]

[1]

int 1

str "apple"

Objects in Memory
Variable Names

Memory address

Step 2

a = [1, “apple”] b = [2, 3] a.append(b) print(a[2][0], b[0]) b[0] = “banana” print(a[2][0], b[0]) b = 0

We created a list named b which references two new integers

list

list

[1]

[1]

[0]

[0]

str "apple"

int 2

int 1

int 3

Objects in Memory
Variable Names

Memory address

Step 3

a = [1, “apple”] b = [2, 3] a.append(b) print(a[2][0], b[0]) b[0] = “banana” print(a[2][0], b[0]) b = 0

The append method of the list causes a reference to the list referenced by b to be added to the end of a a[2] and b are now both ways to access the same list

[2]

list

list

[1]

[1]

[0]

[0]

int 3

str "apple"

int 2

int 1

Objects in Memory