
資料內容:
一、面向對象編程簡介
面向對象編程是一種組織代碼的思想。
一切皆對象;
通過 類(class) 定義對象的模板;
通過 對象(object) 實際使用數(shù)據(jù)與功能。
二、定義類與創(chuàng)建對象
基本語法:
class 類名:
? ?def 方法(self):
? ? ? ?pass
案例
class Student:
? ?def say_hello(self):
? ? ? ?print("你好,我是學生!")
# 創(chuàng)建對象
stu = Student()
stu.say_hello()
輸出
你好,我是學生!