Bird
Raised Fist0

Which statement about arithmetic operator overloading in Python is TRUE?

hard🧠 Conceptual Q10 of Q15
Python - Magic Methods and Operator Overloading
Which statement about arithmetic operator overloading in Python is TRUE?
AOperator overloading allows custom classes to define behavior for operators like +, -, *
BOverloading operators changes their behavior only for built-in types
CYou must always return a primitive type from operator methods
DOperator overloading is not supported for comparison operators
Step-by-Step Solution
Solution:
  1. Step 1: Understand operator overloading scope

    Operator overloading applies to user-defined classes, not built-in types.
  2. Step 2: Clarify return types and supported operators

    Operator methods usually return class instances, and overloading supports arithmetic and comparison operators.
  3. Final Answer:

    Operator overloading allows custom classes to define behavior for operators like +, -, * -> Option A
  4. Quick Check:

    Custom classes can overload arithmetic operators [OK]
Quick Trick: Overloading lets classes define operator behavior [OK]
Common Mistakes:
MISTAKES
  • Thinking overloading affects built-in types
  • Believing operator methods must return primitives
  • Assuming comparison operators can't be overloaded

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes