Logo

Question preview

Class is in functional session

What this preview is

About this preview

Class is in functional session is a medium quant interview question on language knowledge in Python, asked at Quant.

Unlock full access to getcracked

Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.

Understanding Python's operator overloading and method resolution order

This is a medium-difficulty Python language-knowledge question that tests whether you understand how Python resolves operator overloads and converts objects to strings for display. Quant firms use questions like this to verify that candidates have solid foundations in Python semantics, particularly around the interaction between arithmetic operators and string representation.

When you execute print(A+B), Python must first evaluate the addition expression, then convert the result to a string for output. The question probes your knowledge of method resolution order: which dunder method gets called first when an operator is used, how Python falls back to reflected methods when the primary method is unavailable, and which string-conversion method takes precedence when print() needs to display an object.

  • Binary operator protocol (__add__, __radd__) and the left-operand-first rule
  • String representation hierarchy (__str__ vs. __repr__ vs. __format__)
  • Fallback behaviour when methods are missing or return NotImplemented