clone()
Making a separate, independent copy of an object, such as shape.clone() in graphics.py or a list copy with list(a).
In more detail
After cloning, changing the copy leaves the original alone, which is the fix for aliasing bugs. A shallow copy copies only the outer object; nested lists inside are still shared, and copy.deepcopy copies all the way down.
Related terms
- aliasing — Having two or more names that refer to the same object, so a change made through one name shows up through the other.
- mutable — Able to be changed in place after it is created, like most lists, arrays and objects in languages such as Python and JavaScript.
- slice — A copy of a run of items from a string, list or tuple, written s[start:stop], which includes start and stops just before stop.
Taught in
- What A Program Really Is — Hands-on Python: Complete Video Course & Book
- Installing Python On Windows — Hands-on Python: Complete Video Course & Book
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Mutable Objects And Aliases — Hands-on Python: Complete Video Course & Book
- Animation: Loops, Bouncing, Flushing — Hands-on Python: Complete Video Course & Book
- Chapter Two In One Sitting — Hands-on Python: Complete Video Course & Book
- Thirty Questions, One Sneaky Print — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep