How Does This Static Variable Work?

Victor Subervi victorsubervi at gmail.com
Fri Jan 4 11:39:50 EST 2008


Thanks. I'll study that.
Victor

On Jan 4, 2008 12:34 PM, Neil Cerutti <mr.cerutti at gmail.com> wrote:

> On Jan 4, 2008 10:17 AM, Victor Subervi <victorsubervi at gmail.com> wrote:
>
> > Hi;
> > I read this example somewhere, but I don't understand it <:-) Can
> > someone please explain how static variables work? Or recommend a good
> > how-to?
> >
> >
> > import random
> >
> > def randomwalk_static(last=[1]): # init the "static" var(s)
> >
> >   rand = random.random() # init a candidate value
> >
>
> Simulating C's static local variables is the (in)famous application for
> this case of optimization in Python's design.
>
> Consult the following entry in the Python General Programming FAQ for
> further information.
>
>
> http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects
>
> --
> Neil Cerutti
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080104/2084f863/attachment-0001.html>


More information about the Python-list mailing list