Project 11: FAQ Accordion
Python Challenge
Builds on these lessons
Step 1 of 3
Project
A Magic Method: __str__
Give class FAQItem a __str__ method returning a formatted "Q: ... A: ..." string. Magic methods (double-underscore names like __str__) are how Python hooks your class into built-in behavior — print(item) calls __str__ automatically instead of the default, unhelpful <FAQItem object at 0x...>.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
class FAQItem:
def __init__(self, question, answer):
self.question = question
self.answer = answer
def __str__(self):
return f"Q: {self.question}\nA: {self.answer}"
item = FAQItem("How long does shipping take?", "2 business days.")
print(item)