Easy Questions
-
What is the Python Data Model?
-
Why does Python use
len(collection)instead ofcollection.len()?
Why is `len()` not a method in Python? -
What are "dunder" methods? Give an example.
-
What is the purpose of
__len__in a Python class? -
How does
__getitem__enable sequence-like behavior in a class? -
What is the difference between
__repr__and__str__? -
Why is
__repr__important for debugging? -
How can you make an object iterable in Python?
-
What happens if you don’t implement
__bool__in a class? -
What built-in function calls
__abs__?
Medium Questions
-
Explain how
FrenchDeckleverages the Python Data Model to support slicing and iteration. -
Why does
random.choicework onFrenchDeckwithout any extra methods? -
How does
__contains__affect the behavior of theinoperator? -
What is the role of
collections.namedtuplein theFrenchDeckexample? -
How would you modify
FrenchDeckto make it shuffleable? -
Why should you avoid directly calling special methods like
__len__? -
How does
__add__enable vector addition in theVectorclass? -
Why does
Vector.__bool__checkbool(abs(self))instead of justself.xorself.y? -
What is the difference between
__mul__and__rmul__? -
How does Python determine the truth value of an object if
__bool__is not implemented?
Complex Questions
-
How does Python’s handling of
len()differ for built-in types vs. custom classes? -
Explain the concept of the "metaobject protocol" in Python.
-
Why does the
Vectorclass return a new instance in__add__and__mul__instead of modifyingself? -
How could you extend the
Vectorclass to support n-dimensional vectors? -
Discuss the trade-offs between using
abs(self)vs.self.x or self.yinVector.__bool__. -
What are "reversed operators" (e.g.,
__radd__), and when are they used? -
How does Python’s operator overloading compare to other languages like C++ or Java?
-
Why does the Python Data Model avoid arbitrary "magic" method names like
__foo__? -
How could you implement a context manager using
__enter__and__exit__? -
What are the performance implications of using special methods vs. direct method calls?
These questions cover fundamental concepts, practical implementations, and deeper design principles from the chapter, suitable for assessing a candidate’s understanding of Python’s Data Model.

No comments:
Post a Comment