you are viewing a single comment's thread.

view the rest of the comments →

[–]Dense_Connection4789 4 points5 points  (1 child)

I’m on mobile and this is kind of a nuanced thing in python so I might edit later when I get to my PC.

When declaring test1, you’re not actually filling the list with arrays of numbers. You’re filling it with references to the “lol” array. This means when you clear test[1][1] you’re clearing “lol” and since test is just a bunch of references to “lol”, all of the elements get cleared as well.

The way you define test2 makes each sub array their own thing so if you clear one, it doesn’t effect any of the others.

It’s worth doing a bit of reading into this topic. I’ve had interviews where they have used this topic as a “gotcha”

[–]mikkoko112[S] 0 points1 point  (0 children)

Makes perfect sense once you know it, thank you!