How do reference counting and cyclic garbage collection work together in CPython?
Simple meaning
Each object has a refcount
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Python & Django questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Each object has a refcount
Open the full page for Why, Steps, Example and Key takeaway.
Cycles delay reclamation until GC runs, which can retain large graphs longer than you expect.
Open the full page for Why, Steps, Example and Key takeaway.
A list holds every element at once.
Open the full page for Why, Steps, Example and Key takeaway.
__repr__ should be unambiguous and, if practical, look like a constructor call for debugging.
Open the full page for Why, Steps, Example and Key takeaway.
__enter__ runs at the start of a with block and its return value is bound to as.
Open the full page for Why, Steps, Example and Key takeaway.
__getitem__ implements indexing and slicing, and if it raises IndexError, for-loops can treat the object as a sequence.
Open the full page for Why, Steps, Example and Key takeaway.
groupby clusters consecutive items that share a key function's result.
Open the full page for Why, Steps, Example and Key takeaway.
chain concatenates iterables without building an intermediate list, useful when merging query results you already have as iterators.
Open the full page for Why, Steps, Example and Key takeaway.
yield produces iterator values and pauses a generator.
Open the full page for Why, Steps, Example and Key takeaway.
The loop schedules ready callbacks and coroutines, waits on sockets, and resumes them when I/O completes.
Open the full page for Why, Steps, Example and Key takeaway.
args collects extra positional arguments as a tuple.
Open the full page for Why, Steps, Example and Key takeaway.
A generator yields values lazily with yield instead of building a full list in memory.
Open the full page for Why, Steps, Example and Key takeaway.
Model talks to the database, View holds request logic, Template renders HTML.
Open the full page for Why, Steps, Example and Key takeaway.
ORM maps Python model classes to tables and builds SQL for you.
Open the full page for Why, Steps, Example and Key takeaway.
Good for light decoupled side effects
Open the full page for Why, Steps, Example and Key takeaway.
The Global Interpreter Lock allows only one thread to execute Python bytecode at a time in a process.
Open the full page for Why, Steps, Example and Key takeaway.
It memoizes pure functions with a size limit.
Open the full page for Why, Steps, Example and Key takeaway.
It locks rows inside a transaction to avoid race updates.
Open the full page for Why, Steps, Example and Key takeaway.
with guarantees cleanup via __enter__/__exit__ even on errors.
Open the full page for Why, Steps, Example and Key takeaway.
select_related joins forward FK/OneToOne in one query.
Open the full page for Why, Steps, Example and Key takeaway.