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 Object-Oriented Python Advanced Objects Iterable Album

How to use __init__?

Not sure what to do......

iter_album.py
class Album:
    def __init__(self):
        self.songs = []
    def add(self, song):
        self.songs.append(song)
    # insert your code here
    def__iter__(self, song):
        self.songs.yield(song)

1 Answer

Steven Parker
Steven Parker
231,248 Points

Here's a few hints:

  • you won't need to do anything to "__init__" for this challenge
  • there should be a space after the "def" keyword
  • the "__iter__" method should take only "self" as an argument
  • check the syntax — "yield" is a statement keyword, not a method
  • you might also consider using "yield from" so you won't need to create a loop