Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Bickham
1,461 Pointsclass letter
so i just have a silly question but for the code challenge we are suppose make a loop through pattern and our code belongs in the parent class, how does python know what we are looping through if what we need to loop through is in the sub class. i know that a parent class can't inherit what's in the child class. right? this is a silly question and i hope it makes sense.
i just need a little clarification
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsGood question. The challenge asks you to create a __str__
method in Letter
. If this method is not overwritten the child class, it is available to run in the child class as if it were local to the child class. So a method that loops over self.pattern
in the parent class will also work in the child class. Both will operate on the instance attribute pattern
.
Post back if you need more help. Good luck!!!
Andrew Bickham
1,461 PointsAndrew Bickham
1,461 Pointsmake sense make sense make sense thank you