0

So, we know that Python uses a reference system, in order to refer to values in a list. So, if we create a new variable=list[index], the variable points to that list index. But what about when we are slicing a new list? Does the new sliced list use pointers? Or is it a new list in itself?

2

1 Answer 1

1

A list in Python is made of an array of references (plus some bookkeeping data). Slicing allocates a new array, but those copied references still point to the same heap objects.

When you do variable=list[index], the variable does not point to the list index. Rather, it references the same object that the list does at that index (at the time it is looked up; they can be changed independently later).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.