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

Step 0

Memory address

Objects in Memory
Variable Names

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

Initially, there are no variables and no objects

str "apple"

list

int 1

[1]

[0]

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

Step 1

Memory address

Objects in Memory
Variable Names

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

int 2

int 3

list

[1]

[0]

int 1

str "apple"

[1]

[0]

list

Objects in Memory
Variable Names

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

Step 2

Memory address

[2]

int 2

int 3

[1]

[0]

list

int 1

str "apple"

[1]

[0]

list

Objects in Memory
Variable Names

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

Step 3

Memory address