Python类的学习

#!/usr/bin/python
#coding:utf8
class chen():
        name="华仔真帅"
        def fun1(self):     #公有方法可以直接被调用
                print self.name
                print "----------------我是公有方法"
                self.__fun2()
        def __fun2(self):    #私有方法先被本类的公有方法调用,然后外部访问该公有方法
                print self.name
                print "我是私有方法"
        @classmethod
        def classfun(self):
                print self.name
                print "我是类方法"
        @staticmethod
        def staticfun():
                print chen.name
                print "我是静态方法"

#公有方法的访问
public=chen()
public.fun1()
#类方法的访问
chen.classfun()
#静态方法调用
chen.staticfun()


你可能感兴趣的:(类,python)