溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python - 筆記1

發(fā)布時(shí)間:2020-10-11 18:37:29 來源:網(wǎng)絡(luò) 閱讀:803 作者:風(fēng)語(yǔ)2018 欄目:編程語(yǔ)言

1. 筆記

  • 常量為了和變量做區(qū)分,全部采用大寫字母,之間用下劃線連接。
  • 靜態(tài)方法:可以直接用類名來調(diào)用的方法,不需要?jiǎng)?chuàng)建對(duì)象,不會(huì)隱式的傳送self。
  • 根據(jù)面向?qū)ο蟮脑O(shè)計(jì)原則,應(yīng)該將對(duì)象的職責(zé)封裝到類的代碼內(nèi)部,盡量簡(jiǎn)化調(diào)用一方的代碼調(diào)用。

1.1 方法的分類

實(shí)例方法
定義:第一個(gè)參數(shù)必須是實(shí)例對(duì)象,該參數(shù)名一般約定為“self”,通過它來傳遞實(shí)例的屬性和方法(也可以傳類的屬性和方法);
調(diào)用:只能由實(shí)例對(duì)象調(diào)用。

類方法

定義:使用裝飾器@classmethod。第一個(gè)參數(shù)必須是當(dāng)前類對(duì)象,該參數(shù)名一般約定為“cls”,通過它來傳遞類的屬性和方法(不能傳實(shí)例的屬性和方法);
調(diào)用:實(shí)例對(duì)象和類對(duì)象都可以調(diào)用。

靜態(tài)方法

定義:使用裝飾器@staticmethod。參數(shù)隨意,沒有“self”和“cls”參數(shù),但是方法體中不能使用類或?qū)嵗娜魏螌傩院头椒ǎ?br/>調(diào)用:實(shí)例對(duì)象和類對(duì)象都可以調(diào)用。

備注:MAC 安裝pygame報(bào)錯(cuò)

liangkai@ttys000 $ pip install pygame
Collecting pygame
  Using cached https://files.pythonhosted.org/packages/b2/6b/c510f0853765eb2219ca5aa3d416d65bb0dea7cd9bb2984aea0a0e04c24d/pygame-1.9.4.tar.gz
Building wheels for collected packages: pygame
  Running setup.py bdist_wheel for pygame ... error
  Complete output from command /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-wheel-7s7vp6w0 --python-tag cp35:
...............
building 'pygame.sdlmain_osx' extension
    /usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Ddarwin -D_THREAD_SAFE -DENABLE_NEWBUF=1 -I/usr/X11R6/include -I/usr/local/include/SDL -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c src/sdlmain_osx.m -o build/temp.macosx-10.6-intel-3.5/src/sdlmain_osx.o
    In file included from src/sdlmain_osx.m:24:
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:34:10: fatal error: 'CarbonSound/CarbonSound.h' file not found
    #include <CarbonSound/CarbonSound.h>
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    ---
    For help with compilation see:
        https://www.pygame.org/wiki/MacCompile
    To contribute to pygame development see:
        https://www.pygame.org/contribute.html
    ---
    error: command '/usr/bin/clang' failed with exit status 1

    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-record-f5kt4tgo/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/1t/l_shx33n0911n3673wmdkl980000gr/T/pip-install-l6ap1uos/pygame/

解決方法:

pip install pygame==1.9.2
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI