欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python類和方法注釋規(guī)范說(shuō)明

 更新時(shí)間:2022年06月10日 11:01:49   作者:XerCis  
這篇文章主要介紹了Python類和方法注釋規(guī)范說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Python類和方法注釋規(guī)范

這里寫(xiě)圖片描述

這里寫(xiě)圖片描述

注釋風(fēng)格

reStructuredTextPyCharm默認(rèn)

def func(path, field_storage, temporary):
    '''基本描述
    詳細(xì)描述
    :param path: The path of the file to wrap
    :type path: str
    :param field_storage: The :class:`FileStorage` instance to wrap
    :type field_storage: FileStorage
    :param temporary: Whether or not to delete the file when the File instance is destructed
    :type temporary: bool
    :returns: A buffered writable file descriptor
    :rtype: BufferedFileStorage
    '''
    pass

NumPy

def func(path, field_storage, temporary):
    '''基本描述
    詳細(xì)描述
    Parameters
    ----------
    path : str
        The path of the file to wrap
    field_storage : FileStorage
        The :class:`FileStorage` instance to wrap
    temporary : bool
        Whether or not to delete the file when the File instance is destructed
    Returns
    -------
    BufferedFileStorage
        A buffered writable file descriptor
    '''
    pass

Google(官方推薦)

def func(path, field_storage, temporary):
    '''基本描述
    詳細(xì)描述
    Args:
        path (str): The path of the file to wrap
        field_storage (FileStorage): The :class:`FileStorage` instance to wrap
        temporary (bool): Whether or not to delete the file when the File instance is destructed
    Returns:
        BufferedFileStorage: A buffered writable file descriptor
    '''
    pass
風(fēng)格特點(diǎn)適用
reStructuredText用冒號(hào)分隔PyCharm默認(rèn)
NumPy用下劃線分隔傾向垂直,長(zhǎng)而深的文檔
Google用縮進(jìn)分隔傾向水平,短而簡(jiǎn)單的文檔

Sphinx對(duì)NumPy和Google風(fēng)格的對(duì)比,英文不好可以參考中文版

小技巧

在PyCharm中Ctrl+Q可快速查看注釋

代碼規(guī)范(含代碼注釋)

代碼縮進(jìn)和冒號(hào)

注意條件語(yǔ)句必須嚴(yán)格控制縮進(jìn),保證父句和子句的關(guān)系

num = 10
if num>5:
? ? print('yes')
else:
? ? print('no')

空行分隔代碼段

例如if語(yǔ)句判斷、while循環(huán)、for循環(huán)、def函數(shù)、class類等代碼段前后最好留一行(人工分好段落)

# if語(yǔ)句
if num>5:
? ? print('yes')
else:
? ? print('no')
?
# for循環(huán)
for i in (1,2,4):
? ? print(i)
?
# while循環(huán)
while i>3:
? ? print('yes')
? ? i+=1
else:
? ? print('end')
? ??
# 函數(shù)定義
def show():
? ? print(132)
?
# 類定義
class Person:
? ? def show(self):
? ? ? ? print(123)

包、模塊的命名規(guī)范

1. 包——要求統(tǒng)一用小寫(xiě)(相當(dāng)于文件夾)

2.模塊——要求統(tǒng)一用小寫(xiě)(相當(dāng)于文件夾里的文件)

類和對(duì)象的命名規(guī)范

1. 類——嚴(yán)格的駝峰式寫(xiě)法eg.IndexUserPerson

2. 對(duì)象——要求統(tǒng)一用小寫(xiě)

函數(shù)的命名規(guī)范

駝峰式寫(xiě)法 eg.indexUserPerson(不強(qiáng)行)

代碼注釋

1.單行注釋——#

2.多行注釋——(快捷鍵為Ctrl+/)

'''

三對(duì)單引號(hào),python多行注釋符''' 

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

  • Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器

    Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器

    這篇文章主要介紹了Python探索之實(shí)現(xiàn)一個(gè)簡(jiǎn)單的HTTP服務(wù)器,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-10-10
  • pyinstaller打包django項(xiàng)目的實(shí)現(xiàn)步驟

    pyinstaller打包django項(xiàng)目的實(shí)現(xiàn)步驟

    本文主要介紹了pyinstaller打包django項(xiàng)目的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • python使用hdfs3模塊對(duì)hdfs進(jìn)行操作詳解

    python使用hdfs3模塊對(duì)hdfs進(jìn)行操作詳解

    這篇文章主要介紹了python使用hdfs3模塊對(duì)hdfs進(jìn)行操作詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-06-06
  • 使用py2exe在Windows下將Python程序轉(zhuǎn)為exe文件

    使用py2exe在Windows下將Python程序轉(zhuǎn)為exe文件

    這篇文章主要介紹了Windows下用py2exe將Python程序轉(zhuǎn)為exe文件的方法,注意py2exe只是負(fù)責(zé)文件格式的轉(zhuǎn)換,并不能將Python程序編譯為機(jī)器碼,要的朋友可以參考下
    2016-03-03
  • Django admin美化插件suit使用示例

    Django admin美化插件suit使用示例

    這篇文章主要介紹了Django admin美化插件suit使用示例,簡(jiǎn)單介紹了suit的使用界面示例,官方文檔,安裝語(yǔ)句等相關(guān)內(nèi)容,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • Python參數(shù)類型以及常見(jiàn)的坑詳解

    Python參數(shù)類型以及常見(jiàn)的坑詳解

    這篇文章主要介紹了Python參數(shù)類型以及常見(jiàn)的坑詳解,由于之前遇到過(guò)幾次有關(guān)于參數(shù)類型的坑,以及經(jīng)常容易把一些參數(shù)類型搞混淆,現(xiàn)在做一下有關(guān)參數(shù)類型的總結(jié)記錄以及對(duì)之前踩坑經(jīng)歷的分析,需要的朋友可以參考下
    2019-07-07
  • Python可視化之pyechart庫(kù)使用詳解

    Python可視化之pyechart庫(kù)使用詳解

    這篇文章主要介紹了Python可視化之pyechart庫(kù)使用詳解,Pyecharts 提供了一個(gè)簡(jiǎn)單而直觀的 API 接口,使得使用者無(wú)需了解復(fù)雜的 JavaScript 語(yǔ)法,即可通過(guò) Python 代碼實(shí)現(xiàn)高度定制化的圖表設(shè)計(jì),需要的朋友可以參考下
    2023-12-12
  • python?sklearn與pandas實(shí)現(xiàn)缺失值數(shù)據(jù)預(yù)處理流程詳解

    python?sklearn與pandas實(shí)現(xiàn)缺失值數(shù)據(jù)預(yù)處理流程詳解

    對(duì)于缺失值的處理,主要配合使用sklearn.impute中的SimpleImputer類、pandas、numpy。其中由于pandas對(duì)于數(shù)據(jù)探索、分析和探查的支持較為良好,因此圍繞pandas的缺失值處理較為常用
    2022-09-09
  • Python 實(shí)現(xiàn)一個(gè)手機(jī)號(hào)碼獲取妹子名字的功能

    Python 實(shí)現(xiàn)一個(gè)手機(jī)號(hào)碼獲取妹子名字的功能

    這篇文章主要介紹了Python 實(shí)現(xiàn)一個(gè)手機(jī)號(hào)碼獲取妹子名字的功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • python如何按照自己順序讀出文件名

    python如何按照自己順序讀出文件名

    這篇文章主要介紹了python如何按照自己順序讀出文件名問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08

最新評(píng)論