天天看點

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

        print("my can language:%s" % self.language)

Python程式設計:從python中了解面向對象_彭世瑜_新浪部落格
Python程式設計:從python中了解面向對象_彭世瑜_新浪部落格
Python程式設計:從python中了解面向對象_彭世瑜_新浪部落格