Python-圖文課件10_第1頁(yè)
Python-圖文課件10_第2頁(yè)
Python-圖文課件10_第3頁(yè)
Python-圖文課件10_第4頁(yè)
Python-圖文課件10_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第十章Python 編碼規(guī)范PEP 8# Aligned with opening delimiter.foo = long_function_name(var_one, var_two, var_three, var_four)# More indentation included to distinguish this from the rest.def long_function_name( var_one, var_two, var_three, var_four): print(var_one)# easy to match operators with operandsincome

2、 = (gross_wages + taxable_interest + (dividends - qualified_dividends) - ira_deduction - student_loan_interest)用 4 個(gè)空格對(duì)齊代碼參數(shù)換行應(yīng)該與分隔符垂直對(duì)齊每行不應(yīng)超過(guò) 79 個(gè)字符提高閱讀體驗(yàn)可以換行來(lái)縮減長(zhǎng)度適當(dāng)空行增強(qiáng)段落感PEP 8def add_number(number1, number2): calculate the sum of two numbers :param number1: the first number :param number2: the se

3、cond number :return: the sum of the two numbers return number1 + number2print(add_number._doc_)import 順序先后順序?yàn)椋簶?biāo)準(zhǔn)庫(kù)、第三方庫(kù)、本地庫(kù)避免用 * 引入字符串分隔符盡量統(tǒng)一注釋的要求完整、同步文檔字符串 calculate the sum of two numbers :param number1: the first number :param number2: the second number :return: the sum of the two numbers自動(dòng)化工具手動(dòng)檢查

4、調(diào)整費(fèi)時(shí)費(fèi)力pycodestyle命令行工具可以顯示源代碼、相應(yīng)的 PEP8 文本和改進(jìn)意見(jiàn)等PyCharmPEP8 檢查是內(nèi)置功能之一實(shí)時(shí)檢查提醒PEP484 和 PEP526def greeting(name: str) - str: return Hello + name類型提示函數(shù)的參數(shù)和返回值類型有助于 IDE 的代碼提示可以通過(guò) typing 庫(kù)擴(kuò)展變量標(biāo)注和類型提示的語(yǔ)法相似Python3.6 以后的版本才有編輯期生效提示和標(biāo)注都不影響運(yùn)行期from typing import List, Uniondef sort_integers(int_list: ListUnionint, float): int_list.sort(reverse=True)list_to_sort = 1, 2.2, 3.3sort_integers(list_to_sort)print(list_to_sort)# Python 3.6 Variable Annotationsvar2: int = 2a:int = “2.0” # 不會(huì)報(bào)錯(cuò)小結(jié)代碼總是給人看的

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論