有人愿意解释为什么第一种方法不起作用,而第二种方法起作用吗
首先,函数计算最终的调整值
# returns None
def _pareRotation(degs):
if degs > 360:
_pareRotation(degs - 360)
else:
print "returning %s" % degs
return degs
…但返回None
:
print _pareRotation(540)
>> returning 180
>> None
但是,如果我们稍微翻转一下并返回函数
# returns expected results
def _pareRotation(degs):
if degs < 360:
print "returning %s" % degs
return degs
else:
return _pareRotation(degs - 360)
…它工作正常:
print _pareRotation(540)
>> returning 180
>> 180
主要是想知道是什么导致None
从递归循环中弹出
是的,你不会在第一种情况下返回,而且我认为它应该是%d,对于int
在第一种情况下,您不会返回:
相关问题 更多 >
编程相关推荐