What is `weakref.ref()` in Python and why is it used?

Python Hard
Select the correct answer: Single Choice

Key points

  • `weakref.ref()` allows tracking objects without preventing their garbage collection.
  • It is commonly used in observer patterns, caches, and mappings.
  • The method returns the object or None if it has been collected.
  • It is not a thread-safe reference or a copy-on-write reference.

Ready to go further?