发布时间:2019-09-18 07:26:08编辑:auto阅读(1944)
1》当函数没有显式return,默认返回None值
>>> def fun():
print 'ok'
>>> res=fun()
ok
>>> type(res)
<type 'NoneType'>
>>> res==None
True
>>> def func():
print 98
return
>>> f=func()
98
>>> f
>>> type(f)
<type 'NoneType'>
>>> f==None
True
2》和任何其他的数据类型比较是否相等时永远返回false
>>> 'python'==None
False
>>> ''==None
False
>>> 9==None
False
>>> 0.0==None
False
3》执行到return语句时,会退出函数,return之后的语句不再执行。。。但将return语句放在try语句块中,是个例外。。。。
def fun():
print 98
return 'ok'#执行到该return语句时,函数终止,后边的语句不再执行
print 98
def func():
try:
print 98
return 'ok' #函数得到了一个返回值
finally:#finally语句块中的语句依然会执行
print 98
print fun()
print '----------'
print func()
运行结果:
98
ok
----------
98
98
ok
上一篇: V 3 corosync&pacemak
下一篇: 送给Python路途中迷茫的你们
48916
48016
38780
35911
30330
27107
26117
20950
20774
19131
639°
716°
690°
688°
659°
627°
720°
773°
915°
1107°