CommencerCommencer gratuitement

Building a Playlist

Now that you've gotten the hang of building custom iterators, you'll practice creating your own Playlist class, to play your favorite songs.

Cet exercice fait partie du cours

Intermediate Object-Oriented Programming in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

class Playlist:
  def __init__(self, songs, shuffle=False):
    self.songs = songs
    self.index = 0
    
    if shuffle:
      random.shuffle(self.songs)
  
  # Define a magic method that returns the iterator object
  ____ ____(____):
    return ____
Modifier et exécuter le code