为什么此递归函数的基本情况等于N< = 0而不是N> 0?
def xfunction(n):
if n > 0:
print(n % 10)
xfunction(n // 10)
这是我从教科书中进行的功能示例,在回顾了有关递归的信息之后,为什么在此示例中的基本情况不等于N&GT? 0?就像只有n变得小于和不等于0时,该函数将停止执行。
def xfunction(n):
if n > 0:
print(n % 10)
xfunction(n // 10)
This is the function example I am going through from a textbook, after reviewing information about recursion, why is the base case in this example not equal to n > 0? As only if n becomes less than and not equal to 0 then the function will stop executing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
逻辑等效性
与 -
这是作者认为对该特定功能的最佳读取的问题。
这些逻辑等价有许多其他形式 -
与 -
我们可以用真相表证明这一点 -
可以通过研究命题逻辑。
logical equivalence
Is the same as -
It's a matter of preference what the author think reads best for this particular function.
There are many other forms of these logical equivalences -
Is the same as -
We can prove this with a truth table -
The basis for these transformations and and other relationships formed by logical operations can be learned by studying propositional logic.