[Tutor] Persistent values in functions

Andrei Kulakov ak@silmarill.org
Wed, 22 May 2002 04:12:20 -0400


On Tue, May 21, 2002 at 10:58:59PM -0700, Seiji Funai wrote:
> I'd like to know if Python supports persistent values
> in functions:  a variable type that saves its value
> when the function returns, and gives the value when
> the function is called again.  I seem to recall that
> you can do this in C.  Please provide syntax and
> perhaps a simple example.  
> 
> Thanks!
>
There isn't anything exactly like that afaik, but you can use
global vars or instances:

>>> a = 1
>>> def A():
...  global a
...  a += 1
...  print a
... 
>>> A()
2
>>> A()
3

> 
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org