Python的类
# coding=utf-8
__author__ = 'zyt'
class Fruit():
name = None
age = 0
def __init__(self): # 自动被调用
self.name = 'apple'
self.age = 1
print '类名是', self.__class__.__name__
def set_name(self, nm):
self.name = nm
def show_name(self):
print 'name is:', self.name
if __name__ == '__main__':
apple = Fruit()
apple.show_name()
apple.set_name('Red Fuji Apple')
apple.show_name()
print type(apple)
print isinstance(apple, Fruit)
运行结果:
类名是 Fruit
name is: apple
name is: Red Fuji Apple
<type 'instance'>
True