38 questions for “Magic Methods & Operator Overloading”

Found in 1 field. Select a question to see its full answer.

Information Technology

38 questions in 1 technology

#QuestionTechnologyTopicLevel
1What are 'magic methods' (dunder methods) in Python, and why are they called that? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
2How do comparison magic methods like __lt__, __le__, __gt__, and __ge__ support custom sorting? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
3How do context manager magic methods __enter__ and __exit__ work, and what does __exit__'s return value control? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
4How do __iadd__ and other in-place operator methods (__isub__, __imul__) differ from their non-in-place counterparts? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
5How does __slots__ interact with magic methods and instance attribute storage? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
6What is the difference between __str__ and __repr__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
7How do you overload arithmetic operators like + and - using __add__ and __sub__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
8How does __contains__ let you customize the behavior of the 'in' operator? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
9How does __repr__ help with debugging when printing a list of custom objects? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
10What do __eq__ and __hash__ need to satisfy together, and what happens if you only override __eq__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate