天天看点

Python编程:从python中理解面向对象

面向对象的三个属性:

封装:把功能显示出来,隐藏具体实现代码

继承:python支持多继承

多态:不同的人,对同一事物的不同看法

方法:类的一部分,对象调用的函数

函数:可以直接用函数名调用的代码块

装饰器:

@classmethod :调用的时候用类名调用,类似static静态函数

@property:像访问属性一样调用方法,类似属性封装

调用父类的方法:super(类名,self).方法名()

子类类型判断:

isinstance

issubclass

多态要素:

继承

方法重写

#coding:utf-8
class Person(object):
    hobby="play"
    def __init__(self,name,age,weight):
        self.name=name
        self._age=age
        self.__weight=weight
    def get_weight(self):
        return self.__weight
    @property
    def get_age(self):
        return self._age
    @classmethod
    def get_hobby(cls):
        return cls.hobby
    def introduction(self):
        print("my name is :%s"%self.name)
 
class :
    def __init__(self,name,age,weight,language):
        super(
        self.language=language
    def introduction(self):
        print("my can language:%s" % self.language)      
Python编程:从python中理解面向对象
Python编程:从python中理解面向对象
Python编程:从python中理解面向对象