Python的类

来源:互联网 发布:米维斯s和卡马d1c知乎 编辑:程序博客网 时间:2024/06/15 00:24

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.nameif __name__ == '__main__':    apple = Fruit()    apple.show_name()    apple.set_name('Red Fuji Apple')    apple.show_name()    print type(apple)    print isinstance(apple, Fruit)运行结果:类名是 Fruitname is: applename is: Red Fuji Apple<type 'instance'>True

0 0
原创粉丝点击