nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
3 of 6
1Why does id() sometimes appear to be reused between two seemingly unrelated objects?
2Why does modifying a list while iterating over it lead to unexpected behavior?
3What is the difference between copy.copy() behavior on a custom object with __copy__ defined versus one without it?
4What will happen when a closure captures a loop variable, and why do all closures created in the loop end up referencing the same final value?
5Why can True == 1 and False == 0 evaluate to True in Python?
6What is monkey patching, and what risks does it introduce in production codebases?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
03 / 06

What is the difference between copy.copy() behavior on a custom object with __copy__ defined versus one without it?

Difficulty: 9/10
Copy, Shallow Copy, Dunder Methods, Object Protocol

copy.copy uses copy if defined; otherwise falls back to default shallow copy

copy.copy() produces a shallow copy of an object. When the object's class defines copy, copy.copy calls that method and uses its return value as the copy. If copy is not defined, copy.copy falls back to the default behavior: for most objects, it creates a new instance and copies the dict (shallowly). For objects with slots or custom reduce_ex, the default may differ. Defining copy lets you control exactly what is copied, which is useful when the object holds resources, caches, or references that should not be duplicated. The risk is that a poorly implemented copy can break expectations, for example by returning self or by not copying mutable state. Always ensure copy returns a new object of the same type with the desired shallow-copy semantics.

  1. 1

    With copy: copy.copy calls obj.copy() and returns its result.

  2. 2

    Without copy: copy.copy uses the default shallow copy, typically copying dict.

  3. 3

    Shallow copy means nested objects are shared, not duplicated.

  4. 4

    Define copy when you need to control which attributes are copied or to reset caches.

  5. 5

    Define deepcopy for deep copies, which otherwise uses pickle-like recursion.

  6. 6

    Common mistake: returning self from copy, which does not create a copy.

  7. 7

    Common mistake: forgetting to copy mutable attributes in copy, leading to shared state.

  8. 8

    Version note: the copy module and copy protocol have been stable since Python 2.

Scenario Questions

0-2 years experience

  1. 1What does copy.copy do if a class does not define __copy__?
  2. 2Does a shallow copy duplicate nested lists?

2-5 years experience

  1. 1You define __copy__ and return self. What is the problem?
  2. 2You need a copy of an object but want to reset its cache. How do you use __copy__?

5-8 years experience

  1. 1You have a class with a database connection and you want copy.copy to create a new object without the connection. How do you implement __copy__?
  2. 2A custom __copy__ breaks deepcopy. How do you implement both correctly?

8+ years experience

  1. 1Design a copy protocol for a complex object graph that supports both shallow and deep copies with resource management.
  2. 2Explain how copy.copy, __reduce_ex__, and pickling interact for objects with custom state.

Follow-up Questions

  • What is the difference between __copy__ and __deepcopy__?
  • How does copy.copy behave with __slots__?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.