过程定义:过程就是简单特殊没有返回值的函数
这么看来我们在讨论为何使用函数的的时候引入的函数,都没有返回值,没有返回值就是过程,没错,但是在python中有比较神奇的事情
def test01(): msg='hello The little green frog' print msg def test02(): msg='hello WuDaLang' print msg return msg t1=test01() t2=test02() print 'from test01 return is [%s]' %t1 print 'from test02 return is [%s]' %t2
总结:当一个函数/过程没有使用return显示的定义返回值时,python解释器会隐式的返回None,
所以在python中即便是过程也可以算作函数。
def test01(): pass def test02(): return 0 def test03(): return 0,10,'hello',['alex','lb'],{'WuDaLang':'lb'} t1=test01() t2=test02() t3=test03() print 'from test01 return is [%s]: ' %type(t1),t1 print 'from test02 return is [%s]: ' %type(t2),t2 print 'from test03 return is [%s]: ' %type(t3),t3
总结:
返回值数=0:返回None
返回值数=1:返回object
返回值数>1:返回tuple