Python Quest

Track 6 · Lesson 11 of 12

Copying and aliasing: when two names share one list

Understand that assignment shares objects, tell == from is, and choose between shallow and deep copies to avoid mutation bugs.

About 40 minIntermediate4 exercises

You will be able to

  • Explain that assignment makes a second name for the same object, not a copy
  • Tell the difference between == (same value) and is (same object)
  • Make shallow copies with list(), .copy() and slicing, and deep copies with copy.deepcopy()
  • Find and fix bugs caused by shared mutable data, including mutable default arguments

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.