I am comfused about the name behavior of Python in recursion

alister alister.ware at ntlworld.com
Thu Oct 6 06:31:50 EDT 2016


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) gives me 10....1 normally.Why it works? Because of the stack
> memory management?
> 
> Thank you

google local & global variables (this relates to many languages not just 
python)



-- 
Excerpts From The First Annual Nerd Bowl (#1)

JOHN SPLADDEN: Hi, and welcome to the first annual Nerd Bowl in sunny
Silicon Valley.

BRYANT DUMBELL: We're coming to you live from the Transmeta Dome to watch
the battle between the North Carolina Mad Hatters and the Michigan
Portalbacks as they compete for the coveted Linus Torvalds Trophy. 

SPLADDEN: This is shaping up to be one hell of a match. The Mad Hatters --
sponsored by Linux distributor Red Hat -- have been on fire the past
month. But the Andover.Net sponsored Michigan Portalbacks are on a tear as
well, thanks in part to the stellar performance of Rob "Taco Boy" Malda. 

DUMBELL: Taco Boy is quite a star, John. Last week at the Kernelbowl he
blew away the Transmeta Secret Agents when he scored 51 points
singlehandedly in the Flying CompactDiscus round. 

SPLADDEN: But then Mad Hatter's Alan Cox was voted this season's Most
Valuable Hacker in the Eastern Division. So, this game is going to be
quite a show. 



More information about the Python-list mailing list