🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Magic Methods and Properties: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. Which method does len(obj) call?
  2. Q2. What does this print? (code)
  3. Q3. If a class defines only repr, what does print(obj) use?
  4. Q4. Without eq, what does a == b check for two objects of your class?
  5. Q5. What does this print? (code)
  6. Q6. Which decorator writes <=, and = for you from eq and lt?
  7. Q7. What does this print? (code)
  8. Q8. What is the first parameter of a @classmethod?
  9. Q9. When is @staticmethod the right choice?
  10. Q10. Why might objects of a class that defines eq fail to go into a set?