-3

I saw an example online that looks like this:

 def DecimalToBinary(num):

      if num >= 1:
         DecimalToBinary(num // 2)
      print(num % 2, end = '')

print(DecimalToBinary(12))

I'll be happy if someone explain it to me.

Pourixa
  • 3
  • 3

3 Answers3

0

The function will run normally as if you called it outside of it

Bredget
  • 11
  • 4
0

It is called recursion. A type of concept of function calling itself. If it has no proper if statement that terminates the function itself, loop will not end or it will error. In your case it terminated.

01100None
0

This is called recursion. There is no problem as long as there is a break condition, in other words the calls to itself stop at some point. Otherwise you have an infinite loop.

Philip Z.
  • 206
  • 2
  • 6