Python 中class的小例子

class Song():
	def __init__(self,lyrics):
		self.lyrics=lyrics
		
	def sing_a_song(self):
		for line in self.lyrics:
			print(line)
		
			
			
happy=Song(["Happy birthday to you",
             "Happy birthday to you"])
             
       
happy.sing_a_song()

 

class Song(object):
	def __init__(self):
		self.tang="lyrics"
		
	def sing(self):
		print("I wanna sing a song")
		
			
thing=Song()
thing.sing()
print(thing.tang)

  

 

posted @ 2019-05-14 14:58  华小电  阅读(977)  评论(0编辑  收藏  举报