读书人

Python学习札记(四)DocStrings

发布时间: 2012-12-27 10:17:10 作者: rapoo

Python学习笔记(四)DocStrings

#!/usr/bin/python# Filename: func_doc.pydef 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 [b]printMax.__doc__[/b]


它所做的只是抓取函数的__doc__属性,然后整洁地展示给你。你可以对上面这个函数尝试一下——只是在你的程序中包括help(printMax)。记住按q退出help。

读书人网 >perl python

热点推荐