In Python, a variable does not contain a list; it holds a reference to a list object stored somewhere in memory. Think of the name as a label tied to the object rather than a box holding it. This small fact explains one of the most tested behaviours on the PCEP (Certified Entry-Level Python Programmer) exam. When you write b = a where a is a list, Python copies nothing. It ties a second label, b, to the very same list object. Now a and b are two names (aliases) for one list, and a change made through either name is visible through the other.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.