5 6 Python合成屬性

2021-09-24 22:31:19 字數 1417 閱讀 8400

說明:使用 property(fget=nnone, fset=none, fdel=nnone, doc=none) 合成屬性相於例項變數。

class

rectangle

:def

__init__

(self, width, height)

: self.width = width

self.height = height

defgetarea

(self)

:print

('getarea方法'

)return self.width*self.height

# 合成乙個矩形面積的屬性

area =

property

(fget=getarea, doc=

'矩形面積的屬性'

)def

getsize

(self)

:print

('getsize方法'

)return self.width, self.height

defsetsize

(self, size)

:print

('setsize方法'

) self.width = size[0]

self.height = size[1]

# 合成乙個矩形大小的屬性

size =

property

(fget=getsize, fset=setsize, doc=

'矩形大小的屬性'

)

r = rectangle(30,

40)print

(r.area)

# 訪問 area 屬性(實際上呼叫 getarea 方法)

getarea方法

1200

print

(r.size)

# 訪問 size 屬性(實際上呼叫 getsize 方法)

print

('-'*30

)r.size =(5

,6)# 對 size 賦值(實際上呼叫 setsize 方法)

print

('-'*30

)print

(r.size)

# 改變後的 size 屬性

getsize方法

(30, 40)

------------------------------

setsize方法

------------------------------

getsize方法

(5, 6)

Python實現語音合成

from aip import aipspeech api key your api key 你的api key secret key your secret key 你的secret key text input 請輸入轉換為語音的文字 result client.synthesis text,z...

使用Python進行面部合成

int是否檢測並返回人臉關鍵點。合法值為 2 檢測。返回 106 個人臉關鍵點。檢測。返回 83 個人臉關鍵點。不檢測注 本引數預設值為 0 模板位址 合成位址 生成位址 合成指數0 100 print 正在合成第1 2張 print 正在合成第 str index 1 張 for index in...

python 時間模組 56

import time t time.localtime 返回當前時間的九元組 t time.struct time tm year 2018,tm mon 9,tm mday 24,tm hour 14,tm min 47,tm sec 43,tm wday 0,tm yday 267,tm is...