I'm trying to learn OOP in Python but I'm confused about some parts.
class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_a_song(self):
for line in self.lyrics:
print line
def print_x(self):
print x
happy_bday = Song(["Happy birthday to you,",
"I don't want to get sued",
"So I'll stop right there"])
bulls_on_parade = Song(["They'll rally around the family",
"With pockets full of shells"])
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()
x = Song(4)
x.print_x()
print_x() returns:
<__main__.Song object at 0x7f00459b4390>
instead of 4. So I try adding x to the parameters for __init__ and print_x, and changing print x to print self.x in the print_x function plus adding self.x = x to init, but it returns this:
TypeError: __init__() takes exactly 3 arguments (2 given)
I honestly don't know what's gone awry here. But any help would be hugely beneficial to me finally understand OOP.
xat the time of creating instance. something likehappy_bday = Song(["Happy birthday to you,", "I don't want to get sued", "So I'll stop right there"], 'x-value')print_xreturn?