本章我们了看一下Python中的函数、模块、文档字符串
一、函数
1、不带参数的函数
def second():
return "aa\n-------------"
#函数调用
print second()
2、带参数的函数
#带默认值的函数
def first(a="MyGold",b="YOU"):
print "the first function!->%s || %s" %(a,b)
print "-------------"
#函数调用方式
first(b="Hello",a="China")
first(b="we")
first()
运行结果:
二、模块
#1、输出该脚本所在的模块名
print __name__, #加"," 目的消除行尾的换行符
#2、输出模块中定义的标示符<函数,类,变量>
import sys
print dir(sys)
三、文档字符串
def third():
#该注释适用于模块和类,函数
'''
this is function note
------------
'''
print third.__doc__
运行结果: