程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python (VIII) inheritance, method rewriting and dynamic language of Python code

編輯:Python

Three characteristics of object-oriented

encapsulation : Improve the security of the program , Put the data ( attribute ) And behavior ( Method ) Wrapping in class objects . Operate on attributes inside methods , stay
Class object . such , There is no need to care about the specific implementation details inside the method , This isolates the complexity .
stay Pvthon There is no special modifier for private properties in , If the property does not want to be accessed outside the class object , Use two... At the front ”_”.

Inherit : Improve code reusability

polymorphic : Improve the scalability and maintainability of the program

Inherit

Grammar format

class Subclass class name ( Parent class 1, Parent class 2...) :
pass

If a class does not inherit any classes , Default inheritance object
Python Support for multiple inheritance
When you define subclasses , The constructor of the parent class must be called in its constructor

class Person(object): #Person Inherit object class 
def __init__(self,name,age):

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved