An alias is another name for the same object. In Python, assigning one variable to another does not copy the object. This matters most with lists and dictionaries: a change made through one name is visible through every other name. section 28.3
Think of a person known by both a full name and a nickname. The names differ, but they identify the same person. Likewise, two variables can point to one object rather than hold separate objects. section 28.0
Two names, one list
genius = ["einstein", "galileo"] smart = genius genius.append("shakespeare") First, genius points to a list. Next, smart becomes another name for that list—not a copy. Finally, append changes the list itself. Both genius and smart now show ["einstein", "galileo", "shakespeare"]. Calling id() on each name shows the same object ID. section 28.1
Figure 28.2. When the list object ["einstein", "galileo"] is modified through the variable genius, the variable smart also points to the modified list object.
The diagram shows both variable names pointing to the list after it has been changed through one name. section 28.1
Aliasing also applies to immutable objects. If a and b both point to the integer 1, then a = 2 makes a point to a different object; b still points to 1. Reassignment changes a name’s destination. It does not change the object another name points to. section 28.1
When you need a separate list
artists = ["monet", "picasso"] painters = artists.copy() painters.append("van gogh") Here, painters is a copy rather than an alias. Adding an item to painters leaves artists unchanged. A quick check: if the second line were painters = artists, would artists change after the append? Yes—both names would point to the same list. section 28.2 section 28.3
Remember the distinction when passing a dictionary to a function that changes it: changes to the shared object remain visible afterward. Use an alias when shared changes are intended; make a copy when the original must stay unchanged. section 28.1 section 28.2





