Class 重要觀念完整複習
class variables
就是在 class 新增一個變數,associated with class created
所有用這個 class 創造出來的 object 都可以用這個 class variables
How to use list or arrays in Python
Array vs List
Array 需要連續記憶體
Array輪循速度比較快,List輪循速度比較慢
Array無法新增或刪除其中的元素,List可以
99.9% of the time, you'll want to use lists. They're flexible, and good for pretty much every purpose.
However, there is also an array.array class in Python, which is essentially a thin wrapper on top of C arrays.
Predefined Class Variables
像 __doc__
The function’s documentation string, orNone if unavailable
可以用 Triple-quotation marks,在定義 class 的 function 內
__name__
The function's name
__module__
The name of the function was defined in or none
Triple-quotation marks
Defining a documentation in multiple lines
用這個就不需要用換行符號
# 是 python 的評論符號
Inheritance
class Child(Parent):
Parent.__init__(a,b,c原有的)
Inheritance Method
你同樣可以def 一個 method,Child一樣可以繼承
Method Overriding - 但是如果你在Child class 內加了和 Parent 一樣的 method,他就跑 Child 內的 method