日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python docstring是什么

docstring是一種文檔字符串,用于解釋構(gòu)造的作用。我們在函數(shù)、類或方法中將它放在首位來描述其作用。我們用三個單引號或雙引號來聲明docstring。

創(chuàng)新互聯(lián)建站成都網(wǎng)站建設(shè)按需策劃,是成都網(wǎng)站推廣公司,為LED顯示屏提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站推廣熱線:028-86922220

>>> def sayhi():
 """
用該函數(shù)打印Hi
"""
 print("Hi") 
>>> sayhi()
Hi

要想獲取一個函數(shù)的docstring,我們使用它的_doc_屬性

>>> sayhi.__doc__
‘
  This function prints Hi
’

相關(guān)推薦:《python基礎(chǔ)教程》

docstring,不僅可以編寫代碼,同時也能寫出文檔,保持代碼和文檔的一致。

docstring說白了就是一堆代碼中的注釋。

Python的docstring可以通過help函數(shù)直接輸出一份有格式的文檔。

編寫test.py

def printMax(x, y):
    '''Prints the maximum of two numbers.
    The two values must be integers.'''
    x = int(x) # convert to integers, if possible
    y = int(y)
    if x > y:
         print (x, 'is maximum')
    else:
         print (y, 'is maximum')
printMax(3, 5)
print (printMax.__doc__)

命令行輸入 help(test)

import test
5 is maximum
Prints the maximum of two numbers.
    The two values must be integers.
help(test)
Help on module test:
NAME
    test - Created on Sat Jun  2 19:05:08 2018
DESCRIPTION
    @author: linzhiwei02
FUNCTIONS
    printMax(x, y)
        Prints the maximum of two numbers.
        The two values must be integers.
FILE
    /Users/linzhiwei02/Desktop/test.py

網(wǎng)站標(biāo)題:創(chuàng)新互聯(lián)Python教程:python docstring是什么
URL地址:http://m.5511xx.com/article/dhpejih.html