QuizzesMutability, Shallow Copy & Deep Copy — Concept Check
intermediate
python

Mutability, Shallow Copy & Deep Copy — Concept Check

Questions on Mutability, Shallow Copy & Deep Copy. Assignment shares, copy() duplicates one level, deepcopy() duplicates everything — knowing which you need prevents the most common "my data changed by itself" bugs.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Mutability, Shallow Copy & Deep Copy — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You have a list of lists in Python. If you perform a shallow copy and modify a nested list, what happens?

    • AThe original list reflects the changes.
    • BOnly the copied list reflects the changes.
    • CNeither list reflects the changes.
    • DBoth lists reflect the changes.
  2. 2.A developer uses `copy.deepcopy()` on a complex data structure. What is the main advantage of this approach?

    • AIt prevents any changes in the original data structure.
    • BIt allows changes to propagate to the original data structure.
    • CIt is faster than a shallow copy.
    • DIt ensures that changes to the copy do not affect the original.
  3. 3.A function modifies a list passed as an argument by appending an element. What can you infer?

    • AThe original list is modified.
    • BThe function received a copy of the list.
    • CThe original list remains unchanged.
    • DThe function is pass-by-value.
  4. 4.What happens when you rebind a parameter inside a function in Python?

    • AThe original argument remains unchanged.
    • BThe original argument is modified.
    • CBoth the original and the parameter are modified.
    • DThe parameter is deleted.
  5. 5.A developer mistakenly believes that assignment in Python copies objects. What is the actual behavior?

    • AAssignment creates a deep copy.
    • BAssignment shares references, not copies objects.
    • CAssignment is identical to deepcopy().
    • DAssignment creates a shallow copy.
  6. 6.Which operation would you use to ensure a nested list structure is entirely independent of the original?

    • ADeep copy
    • BAssignment
    • CSlicing
    • DShallow copy
  7. 7.A developer uses slicing `[:]` on a list of strings. What type of copy is created?

    • ANo copy, just a reference.
    • BImmutable copy, preventing changes.
    • CDeep copy, duplicating everything.
    • DShallow copy, sharing inner objects.
  8. 8.What happens if you append an element to a list inside a function without copying it first?

    • AThe caller's list remains unchanged.
    • BThe function throws an error.
    • CThe caller's list is modified.
    • DA new list is created inside the function.