文章标题

class Song(object):   
    def __init__(self):
        pass
    def sing_song(self):
        for line in lyrics:
            print line
lyrics = ['hey','jude']       
m = Song()
m.sing_song()

Python的类可以使用全局变量

class Song(object):
    lyrics = ['hey','jude']
    def __init__(self):
        pass
    def sing_song(self):
        for line in self.lyrics:
            print line

m = Song()
m.sing_song()

python的类也可以使用类内部的变量

你可能感兴趣的:(文章标题)