0
点赞
收藏
分享

微信扫一扫

Python编程:从python中理解面向对象_彭世瑜_新浪博客

面向对象的三个属性: 封装:把功能显示出来,隐藏具体实现代码 继承:python支持多继承 多态:不同的人,对同一事物的不同看法

方法:类的一部分,对象调用的函数 函数:可以直接用函数名调用的代码块

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

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

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

子类类型判断: isinstance issubclass

多态要素: 继承 方法重写


  1. #coding:utf-8
  2. class Person(object):
  3.     hobby="play"
  4.     def __init__(self,name,age,weight):
  5.         self.name=name
  6.         self._age=age
  7.         self.__weight=weight
  8.     def get_weight(self):
  9.         return self.__weight
  10.     @property
  11.     def get_age(self):
  12.         return self._age
  13.     @classmethod
  14.     def get_hobby(cls):
  15.         return cls.hobby
  16.     def introduction(self):
  17.         print("my name is :%s"%self.name)

  18. class :
  19.     def __init__(self,name,age,weight,language):
  20.         super(
  21.         self.language=language
  22.     def introduction(self):
  23.         print("my can language:%s" % self.language)

Python编程:从python中理解面向对象_彭世瑜_新浪博客_python​​


Python编程:从python中理解面向对象_彭世瑜_新浪博客_python_02​​



Python编程:从python中理解面向对象_彭世瑜_新浪博客_类_03​​


举报

相关推荐

0 条评论