Last Updated: December 6, 2025
29 quizzes
Complete the code to check how many references currently point to the object stored in data
count = sys.getrefcount(dataClick an option to fill the blank:
Complete the code so that the weak reference returns the current target object when accessed
target = cache_refClick an option to fill the blank:
Complete the code to obtain the size in bytes of the object stored in payload
size_in_bytes = sys.getsizeof(payloadClick an option to fill the blank:
Which part of memory does Python primarily use to store objects like lists and dictionaries?
What is the main purpose of Python's garbage collector beyond reference counting?
Which function lets you manually trigger Python's cyclic garbage collection?
What happens to an object when its reference count reaches zero?
Which Python module is specifically used to create weak references?
Why might you use weak references in an in-memory cache?
What is a key benefit of writing a C extension for a CPU-bound Python function?
Which Python standard library module provides an FFI for calling functions in shared libraries?
What file extension is commonly used for Cython source files?
Which statement about reference counting in CPython is correct?
When calling a C function using ctypes, why should you set argtypes and restype?
Order the steps to create and use a simple C extension function in Python.
Drag and drop to reorder, or use the arrows.
Order the steps to call a function from a shared C library using ctypes.
Drag and drop to reorder, or use the arrows.
What is the output of this code involving reference counts?
1import sys
2items = []
3count1 = sys.getrefcount(items)
4alias = items
5count2 = sys.getrefcount(items)
6print(count2 - count1)What is the output of this code using weak references?
1import weakref
2class Cache:
3 pass
4obj = Cache()
5ref = weakref.ref(obj)
6obj = None
7print(ref() is None)What is the output of this code using gc to demonstrate a cycle?
1import gc
2class Node:
3 def __init__(self):
4 self.ref = None
5a = Node()
6b = Node()
7a.ref = b
8b.ref = a
9del a, b
10unreachable_before = len(gc.garbage)
11gc.collect()
12unreachable_after = len(gc.garbage)
13print(unreachable_after >= unreachable_before)What is the output when inspecting sizes of two integers?
1import sys
2x = 10
3y = 10
4print(sys.getsizeof(x) == sys.getsizeof(y))What is the output of this Cython-like performance test written in pure Python?
1def sum_of_squares(n):
2 total = 0
3 for i in range(n):
4 total += i * i
5 return total
6print(sum_of_squares(3))Find the bug in this code that tries to track reference counts.
Click on the line(s) that contain the bug.
import sys def track(obj): before = sys.getrefcount(obj) temp = obj after = sys.getrefcount(obj) return before, afterFind the bug in this ctypes code that calls a C function returning an int.
Click on the line(s) that contain the bug.
import ctypes lib = ctypes.CDLL('mylib.so') result = lib.compute(5)print(result + 1)Match each concept with its most accurate description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each tool with how it integrates C/C++ code with Python.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to store objects in a cache that does not keep them alive unnecessarily.
import weakrefclass Image: def __init__(self, name): self.name = namethumbnails = (Image)preview = Image('logo.png')thumbnails['logo'] = previewpreview = Noneprint(thumbnails['logo']() is )Click an option to fill blank 1:
Complete the Cython build script to compile a .pyx module.
from setuptools import setupfrom Cython.Build import setup( ext_modules=())Click an option to fill blank 1:
Click the line that creates a circular reference that the garbage collector must handle.
Click on the line to select.
class Node: def __init__(self): self.ref = None first = Node()second = Node()first.ref = secondsecond.ref = firstClick the line that creates a strong reference which prevents the object from being garbage collected while it exists.
Click on the line to select.
import weakref class Data: pass obj = Data()ref = weakref.ref(obj)keep = obj