global variables 全局访问
member variables 类变量,类的所有对象共享
instance variables 对象变量,只对某一对象有用
类变量写在class语句下面和def语句并列,调用时用 类.类变量
对象变量用self.对象变量声明,调用时一样
#!/usr/bin/python
# Filename: objvar.py
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
self.name = name
print '(Initializing %s)' % self.name
# When this person is created, he/she
# adds to the population
Person.population += 1
def __del__(self):
'''I am dying.'''
print '%s says bye.' % self.name
Person.population -= 1
if Person.population == 0:
print &#