python函數小知識

在咱們寫一些腳本的時候必定要加上註釋,否則時間久了可能本身都記不清楚當時這些代碼是作什麼用的了,在python中,咱們也會對一些函數作一些描述,可是有時候不打開代碼是看不到每一個函數的解釋的,python提供了一個很方便的工具docstrings(documentation strings)文檔字符,能夠很方便的打印出函數的描述,我本身寫了一個小例子。python

#-*-coding:utf-8-*-
#author:yangdong
def print_documentation(x,y):
    '''this is a function to learn how to make __doc__
    to print the documentation!!
    the function's result is the max number'''
    x=int(x)
    y=int(y)
    if x > y:
        return x
    elif x == y:
        return  "the tow number is equal!"
    else:
        return y

print(print_documentation(4,6))
print(print_documentation.__doc__)

運行結果:函數

6
this is a function to learn how to make __doc__
    to print the documentation!!
    the function's result is the max number
相關文章
相關標籤/搜索