Friday, 15 February 2013

More Confusion With OOP in Python -


Why do I have to give the song to print as 4 for x but not for two strings? I finally understand the parameters and satisfy them, but I do not know how to print songs for X in addition to the BulldogOnPerd and MemoryContents other than memory address.

  class song (): def __init __ (self, song, x): self.lyrics = lyrics # self.x = x def sing_me_a_song (self): for the line in self: print Line def print_x (self): print x.lyrics happy_bday = song (["Happy birthday to you", "I do not want to sue", "I will stop there"], 'x-value') bulls_on_parade = song ["They will rally around the family", "packets full of shells"], 'x-value'] happy_bound. Sing_me_a_song () bulls_on_parade.sing_me_a_song () def song (args): pass x = song (song = 4, X = song) x come in this snippet of code    

being a function. x lyrics for code> will pass this address to work (this is not entirely true, but for now, do it) to x as the value of the parameter.

Bol = 4 is different because the Python function separates between call logic names and variable names.

  def song (args): pass x = song (song = 4, x = song)  

In fact, if you do this in your code

 

  x = song (song = song) print x.lyrics  

You will see something like this:

< Pre> & lt; Function song 0x107b9d1b8 & gt;

No comments:

Post a Comment