Python正課68 實現物件導向程式設計

2022-01-30 04:06:14 字數 1030 閱讀 2363

注意:類體** 是在 類定義階段就會立即執行的

class student:

# 1.變數的定義

stu_school = 'oldboy'

# 2.功能的定義

def tell_stu_info(stu_obj):

print('學生資訊 - 名字:%s 年齡:%s 性別:%s' % (

stu_obj['stu_name'],

stu_obj['stu_age'],

stu_obj['stu_gender']

))def set_info(stu_obj, x, y, z):

stu_obj['stu_name'] = x

stu_obj['stu_age'] = y

stu_obj['stu_gender'] = z

# print('*****==>')

# 屬性訪問的語法

# 1.訪問資料屬性

# 2.訪問函式屬性

# print(student.__dict__) #

# print(student.stu_school) # oldboy

# 再呼叫類產生物件

stu1_obj = student()

stu2_obj = student()

stu3_obj = student()

# stu1_obj.__dict__['stu_name'] = 'eogn'

# stu1_obj.__dict__['stu_age'] = 16

# stu1_obj.__dict__['stu_gender'] = 'male'

# print(stu1_obj.__dict__) #

stu1_obj.stu_name = 'eogn'

stu1_obj.stu_age = 16

stu1_obj.stu_gender = 'male'

print(stu1_obj.__dict__) #

python 物件導向 python是物件導向嗎

python是一種物件導向 解釋型計算機程式語言,由guido van rossum於1989年底發明,第乙個公開發行版發行於1991年,python 源 同樣遵循 gpl gnu general public license 協議。python語法簡潔而清晰,具有豐富和強大的類庫。但實際上面向過程...

python通過Dlib庫實現人臉68點特徵點標記

import cv2 影象處理庫 import dlib 人臉識別庫 from skimage import io 影象處理庫 功能 人臉檢測畫框 引數 無 返回值 預設的人臉檢測器 detector dlib.get frontal face detector print detector pre...

python 物件導向 實現棧

要求 棧的方法 入棧 出棧 取棧頂元素 棧的長度 判斷棧是否為空 顯示棧的元素 class stack def init self self.stack 屬性只用乙個空列表 def push self,value return true def pop self if self.stack 獲取出棧...