首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python学习札记(四)DocStrings

2012-12-27 
Python学习笔记(四)DocStrings#!/usr/bin/python# Filename: func_doc.pydef printMax(x, y):Prints th

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。

热点排行