在Python中有一個奇妙的特性,文檔字串,又稱為DocStrings。用它可以為我們的模組,類,函數添加說明性的文字,使程式易讀易懂,更重要的是可以透過Python自帶的標準方法將這些描述性文字訊息輸出。下面舉例說明。
'''This is My own Module Date:2011-09-07 Author:Chris Mao This is description information''' class TestClass: '''This is TestClass' DocStrings''' def func1(): '''this is func1's DocStrings''' pass def func2(): '''this is func2''' print "this is func2" print func2.__doc__