function with a state

Kent Johnson kent37 at tds.net
Sun Mar 6 13:20:14 EST 2005


Patrick Useldinger wrote:
> Kent Johnson wrote:
> 
>>> globe=0
>>> globe=myfun(globe)
>>> def myFun(var):
>>>   return var+1
>>
>>
>>
>> This mystifies me. What is myfun()? What is var intended to be?
> 
> 
> myfun is an error ;-) should be myFun, of course.
> 
> var is parameter of function myFun. If you call myFun with variable 
> globe, all references to var will be replaced by globe inside function 
> myFun.

Oh. I thought there was some deep magic here that I was missing :-)

You also have to define myFun before you call it...

def myFun(var):
   return var+1

globe = 0
...
globe = myFun(globe)

Kent



More information about the Python-list mailing list