On Wed, 05 Oct 2016 17:30:22 -0700, 380162267qq wrote:
> Google told me Python name is a label attaching to the object.
> But in this recursive function,the name 'a' will point to different
> number object.
>
> def rec(a):
> a+=1 if a<10:
> rec(a)
> print(a)
>
> rec(0)
38016226...@gmail.com wrote:
def rec(a):
a+=1
if a<10:
rec(a)
print(a)
rec(0) gives me 101 normally.Why it works? Because of the stack memory
management?
Yes. There isn't just one 'a' here, there's a different one
each time rec is called.
Thank yo
38016226...@gmail.com writes:
> Google told me Python name is a label attaching to the object.
Well, “Google told me” has no necessary bearing on whether it's true :-)
so that's not a good citation to give.
If you need to know what Python terminology means, the Python
documentation is better.
Google told me Python name is a label attaching to the object.
But in this recursive function,the name 'a' will point to different number
object.
def rec(a):
a+=1
if a<10:
rec(a)
print(a)
rec(0) gives me 101 normally.Why it works? Because of the stack