記錄函數(shù),在函數(shù)的開頭寫下字符串,它就會(huì)作為函數(shù)的一部分進(jìn)行存儲(chǔ),這稱為文檔字符串,如
def square(x): 'Caculates the square of the number x.' return x*x
>>> square.__doc__
'Caculates the square of the number x.'
help -- 在交互式解釋器中使用會(huì)得到關(guān)于函數(shù)包括它的文檔字符串的信息,如
>>> help(square)
Help on function square in module __main__:
square(x)
Caculates the square of the number x.
所有的函數(shù)都返回了東西:當(dāng)不需要它們返回值的時(shí)候,它們就返回None。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注