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 trial

Python

Andrew Bickham
Andrew Bickham
1,461 Points

class 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

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern


class S(Letter):
    def __init__(self):
        pattern = ['.', '.', '.']
        super().__init__(pattern)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Good 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
Andrew Bickham
1,461 Points

make sense make sense make sense thank you