OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why is "else" redundant here in recursion? [duplicate]

  • Thread starter Thread starter Tuff Fish
  • Start date Start date
T

Tuff Fish

Guest
Learning python, I got a question why "else" here is redundant and not needed

Code:
def print_n(s, n):
    if n <= 0:
        return
**else:**
    print(s)
    print_n(s, n-1)
print_n("spam", 5)
<p>Learning python, I got a question why "else" here is redundant and not needed</p>
<pre><code>def print_n(s, n):
if n <= 0:
return
**else:**
print(s)
print_n(s, n-1)
print_n("spam", 5)
</code></pre>
 
Top