python 对象

__author__ = 'admin'
# -*- coding: utf-8 -*-

class Ren():
    name="human"
    def say(self):
        print('can speak')


class Chinese(Ren):
    name = 'chinese people'

#多重继承 使用先继承者的属性  ,可调整顺序实现想要的属性 ,且只
#继承第一个的 __init__ 方法
class Beijing(Chinese,Ren):
    pass

Ren.name='a human'
print(Ren.name)

per1=Chinese()
per1.say()
print(per1.name)
print( isinstance(per1,Ren))

print(Beijing.name)


#加双下划线声明为私有,外部不可直接使用
#类方法  @classmethod
class Ren(object):
    '''
    Ren class desc
    '''

    name = 'ren'
    __money=0
    def __init__(self,n='empty'):
        self.name=n

    #析构函数
    def __del__(self):
       pass


    # 类方法 是类本身
    @classmethod
    def classmethod(self):
        print('%s run'% self.name )


    # 公有方法 参数是实例
    def pubMethod(self):
        print('%s run'% self.name )

    #私有方法
    def __speak(self):
        print 'speak'

    #静态方法 往往没有参数 不跟类或实例有任务关系
    @staticmethod
    def staticMethod():
        print('static method %s'% Ren.name)

 


r=Ren('xiaoming')

r.pubMethod()

Ren.classmethod()

Ren.staticMethod()

 

 

posted @ 2013-12-11 11:55  zhangxiaodel  阅读(151)  评论(0编辑  收藏  举报