Python Introducing Lists Using Lists Mutability

Pranshu Mittal
Pranshu Mittal
3,585 Points

When using inventory[:] instead of inventory.copy() same result is obtained. Why?

i tried using inventory[:] or inventory[0:] while removing all the elements of the list and the result obtained is [] similar to that of inventory.copy() even though python is not creating another object. So why is the giving the exact same result?

1 Answer

Steven Parker
Steven Parker
182,603 Points

A slice does create another object, and one with no arguments does exactly the same thing as the "copy" method.