我不知道在不需要时跳过return None
是不是坏方法。跳过“返回无”可以吗?
实施例:
def foo1(x):
if [some condition]:
return Baz(x)
else:
return None
def foo2(x):
if [some condition]:
return Baz(x)
bar1 = foo1(x)
bar2 = foo2(x)
在这两种情况下,当条件为假,功能将与None
返回。
也有助于符合'import this':P – 2010-10-26 20:19:55
关于'__init__'方法的结尾?既然你不能'返回None',那么最好是有'return'还是什么也不做? – dln385 2010-10-26 20:32:34
@ dln385:你可以在__init__中返回None,实际上这就是return的作用。 – adw 2010-10-26 20:35:46