python 知识点整理(五)
本文只是对python部分知识点进行学习和整理
本篇主要是针对python的Object Oriented Programming的总结
本文目录
object/class/inheritance
objects
- object: An object has a unique identity, state, and behaviours
- In Python, everything is an object: number, string, etc
- can use id() and type() to get information about an object
- ID位置一般不会改变
- 数据类型会根据input进行决定
- A variable in Python is actually a reference to an object.变量是对对象的引用
class
class name
data fields private/public
- private data fields are defined with two leading underscores(__). The same as a private
method
methods
- A class provides a special method, init(), which is called initializer(给定默认初始值)
- Initializer is invoked when an instance of the class is created
inheritance
Object-oriented programming (OOP) allows you to define new classes from existing classes. This is called inheritance
Polymorphism and dynamic binding
- Polymorphism means that an object of a subclass can be passed to a parameter of a superclass type
- 多态性意味着子类的对象可以传递给超类类型的参数
- Python decides which method is invoked at runtime. This is known as dynamic binding
- Python决定在运行时调用哪个方法。这就是所谓的动态绑定
recursion 迭代
- Linear Recursion
- If a recursive function is designed so that each invocation of the body makes at most one new recursive call, this is known as linear recursion
- Multiple recursion
- When a function makes two or more recursive calls, we say that it uses multiple recursion