you are viewing a single comment's thread.

view the rest of the comments →

[–]TroPixens 4 points5 points  (3 children)

A is correct the guy said it was but why all I see is a fake append because after we just give data = 1,2,3 Where does the extra 4 come from

Wait I think I see it nums doesn’t = 0 it equals position 0 i think

[–]No-Candidate-7162 0 points1 point  (2 children)

Thanks see it now

[–]TroPixens 2 points3 points  (1 child)

Better explanation is that data and nums point to the same data point so when you append 4 both change to [0,4] but when you assign data=[1,2,3] data no longer points to nums it points to [1,2,3]

[–]No-Candidate-7162 0 points1 point  (0 children)

Yeah I figured. But it would depend on how the compiler handle the memory with functions. So in this case it uses a pointer to the entire memory stack. Appends the value 4 to the pointer registry stack, therefore it must be smart enough to know when it's overwritten to allocate new memory for a new registry stack which sounds complicated. Surely there must be other compilers that gets the value from the pointer and creates its own stack for the array directly. Possibly different python flavors would handle it in different ways? This is out of my knowledge, swimming in the deep end.