0
Is it really matter to care about how the space is manage in Python?
Hello, thank you for your response. I wonder why the second one is different compare to the first one. #1) def one(y): print(y*8) one(2) #2 def one(y): print(y*8) one(2) Python was able to show the output 16 for the #2 but shows "no output" for the #1
1 Odpowiedź
+ 2
The first one defines a function and then calls it. However, the second one calls the function *within* the function, making it recursive.
def one(y):
print(y*8)
one(2)
>>>No output
The function is never called though (hence no output), which is actually good;
def one(y):
print(y*8)
one(2)
one(2)
>>>16
>>>16
>>>16
... #Infinite loop
If you call the function within the function, it is recursive (as mentioned earlier), hence it will call itself. So it will print 16, then call itself (with a value of 2), printing 16, calling itself... for infinity. There's the small vital difference between the two: that small indentation.
Hope this helped! 😉