Sobes.tech
Junior — Senior

Why changing one list affects another: assignment details in Python

livecode

Task condition

In this task, you need to understand how list assignment works in Python and why changing one list affects the other. Consider the following example and explain what happens at the level of references and mutable objects.

source = [1, 2, 3, 4]
alias = source
alias.append(5)
print(source)

Describe how Python handles variables, what objects are created, why source outputs [1, 2, 3, 4, 5], and how simple copying differs from creating an independent list.