Advertisement
Dmitry_Dronov

songs

Apr 26th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. class Song:
  2.     tags = []
  3.     def __init__(self, artist, song):
  4.         self.artist = artist
  5.         self.song = song
  6.  
  7.     def add_tags(self, *args):
  8.         self.tags.extend(args) # теги мы определяем только в конструкторе
  9.  
  10.  
  11. song1 = Song('Shakey Graves', 'Roll the Bones')
  12. song1.add_tags('Americana', 'Country') # и теги не определяем нигде в экземпляре
  13.  
  14. song2 = Song('Neuromonah Feofan', 'Holodno v lesu')
  15. song2.add_tags('Russian', "Drum'n'Base") #
  16.  
  17. print(song2.tags) # поэтому при выводе тегов оказывается что они все находятся не в разных списках а в одном
  18. # ['Americana', 'Country', 'Russian', "Drum'n'Base"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement