Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14185

Why does Online Python Tutor present this immutable integer as two different integers graphically?

$
0
0

In Fluent Python, By Luciano Ramalho, Chapter 8, Copies Are Shallow by Default, there is an example:

>>> listOne = [3, [55, 44], (7, 8, 9)]>>> listTwo = list(listOne)>>> listTwo[3, [55, 44], (7, 8, 9)]>>> listTwo == listOneTrue>>> listTwo is listOneFalse

The author suggests that we should run through this code using Online Python Tutor to see what is happening step by step.

I executed the first two lines using Online Python Tutor, and this is the screen shot I got:

enter image description here

What confuses me is:

All three elements from the each list, the immutable integer, the list and the tuple are actually the same, e.g.

listOne[0] is listTwo[0] #TruelistOne[1] is listTwo[1] #TruelistOne[2] is listTwo[2] #True

So why the graph shows two separate 3s at the beginning of their respective list?


Viewing all articles
Browse latest Browse all 14185

Trending Articles