![Python 的 OOP 概念分析學(xué)習(xí)_第1頁(yè)](http://file4.renrendoc.com/view3/M03/14/25/wKhkFmYcqeOAXCKUAACVMe46Pgo497.jpg)
![Python 的 OOP 概念分析學(xué)習(xí)_第2頁(yè)](http://file4.renrendoc.com/view3/M03/14/25/wKhkFmYcqeOAXCKUAACVMe46Pgo4972.jpg)
![Python 的 OOP 概念分析學(xué)習(xí)_第3頁(yè)](http://file4.renrendoc.com/view3/M03/14/25/wKhkFmYcqeOAXCKUAACVMe46Pgo4973.jpg)
![Python 的 OOP 概念分析學(xué)習(xí)_第4頁(yè)](http://file4.renrendoc.com/view3/M03/14/25/wKhkFmYcqeOAXCKUAACVMe46Pgo4974.jpg)
![Python 的 OOP 概念分析學(xué)習(xí)_第5頁(yè)](http://file4.renrendoc.com/view3/M03/14/25/wKhkFmYcqeOAXCKUAACVMe46Pgo4975.jpg)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Lecture-7
OOPConceptswithPython
sazzad@diucse
Content
Definesclassandobject
Encapsulationanddatahiding
Controllingaccesstoattributes
Propertiesfordataaccess
WhatisObject
Objecthaveattributes(variables)andbehaviour(Methods/Function)
Attributesare:name,colouretc.
Behavior:running,drinkingetc.
Whatisclass?
Aclassisblueprintformwhichindividualobjectarecreated
namecolour
runningStyle()
drinkingMlikStyle()
SyntaxofCreatingPythonClass
CreatePersonClass
Output:John
36
TheSelfParameter
Theselfparameterisareferencetothecurrentinstanceoftheclass,andisusedtoaccessvariablesthatbelongstotheclass.
Itdoesnothavetobenamedself,youcancallitwhateveryoulike,butithastobethefirstparameterofanyfunctionintheclass.[itworklikeget()methodinjava]
The
init
Function
The
init() functioniscalledautomaticallyeverytimethe
classisbeingusedtocreateanewobject.
Allclasseshaveafunctioncalled
init() ,whichisalways
executedwhentheclassisbeinginitiated.[itworklikeconstructorinjava]
CreateObject
UnderstandingObjectAttributeandBehavior
EncapsulationandDataHiding
Encapsulationmeansthattheinternalrepresentationofanobjectisgenerallyhiddenfromviewoutsideoftheobject’sdefinition.
Aclassisanexampleofencapsulationasitencapsulatesallthedatathatismemberfunctions,variablesetc.
InPython,alldataattributesareaccessible.Youuseattributenamingconventionstoindicatethatattributesshouldnotbeaccesseddirectlyfromclientcode.
Encapsulation(Public)
Publicmembers(generallymethodsdeclaredinaclass)areaccessiblefromoutsidetheclass.Theobjectofthesameclassisrequiredtoinvokeapublicmethod.
AllmembersinaPythonclassarepublicbydefault.Anymembercanbeaccessedfromoutsidetheclassenvironment.
Encapsulation(Protected)
Protectedmembersofaclassareaccessiblefromwithintheclassandarealsoavailabletoitssub-classes.Nootherenvironmentispermittedaccesstoit.Thisenablesspecificresourcesoftheparentclasstobeinheritedbythechildclass.
Python'sconventiontomakeaninstancevariableprotectedistoaddaprefix_(singleunderscore)toit.Thiseffectivelypreventsittobeaccessed,unlessitisfromwithinasub-class.
Encapsulation(Private)
Pythondoesn'thaveanymechanismthateffectivelyrestrictsaccesstoanyinstancevariableormethod.Pythonprescribesaconventionofprefixingthenameofthevariable/methodwithsingleordoubleunderscoretoemulatethebehaviorofprotected
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年透明螺絲批項(xiàng)目可行性研究報(bào)告
- 廣州2025年廣東廣州市天河區(qū)珠江新城獵德幼兒園編外教輔人員招聘3人筆試歷年參考題庫(kù)附帶答案詳解
- 2025至2031年中國(guó)自行車(chē)撐絲行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025年滌粘印染面料項(xiàng)目可行性研究報(bào)告
- 2025年機(jī)械壓力式燃燒器項(xiàng)目可行性研究報(bào)告
- 恩施2025年湖北恩施高中及相關(guān)縣市高中招聘48人筆試歷年參考題庫(kù)附帶答案詳解
- 德陽(yáng)2025年四川德陽(yáng)廣漢市衛(wèi)生系統(tǒng)事業(yè)單位招聘編外聘用人員44人筆試歷年參考題庫(kù)附帶答案詳解
- 2025年農(nóng)業(yè)吸水膠管項(xiàng)目可行性研究報(bào)告
- 2025年不銹鋼中式火鍋?lái)?xiàng)目可行性研究報(bào)告
- 2025至2030年中國(guó)集裝箱襯袋數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 【正當(dāng)防衛(wèi)的限度條件及司法認(rèn)定問(wèn)題淺析10000字(論文)】
- Unit 4 Time to celebrate 教學(xué)設(shè)計(jì)-2024-2025學(xué)年外研版英語(yǔ)七年級(jí)上冊(cè)
- 市政管網(wǎng)工程投標(biāo)方案(技術(shù)方案)
- 健康檔案模板
- 購(gòu)買(mǎi)演唱會(huì)門(mén)票的合同模板
- DB32-T 4790-2024建筑施工特種作業(yè)人員安全操作技能考核標(biāo)準(zhǔn)
- 2022年安徽阜陽(yáng)太和縣人民醫(yī)院本科及以上學(xué)歷招聘筆試歷年典型考題及考點(diǎn)剖析附帶答案詳解
- 頂管工程施工及驗(yàn)收技術(shù)標(biāo)準(zhǔn)
- 【基于現(xiàn)金流的企業(yè)財(cái)務(wù)風(fēng)險(xiǎn)探究文獻(xiàn)綜述4100字】
- TD/T 1036-2013 土地復(fù)墾質(zhì)量控制標(biāo)準(zhǔn)(正式版)
- 安全警示教育的會(huì)議記錄內(nèi)容
評(píng)論
0/150
提交評(píng)論