why function got dictionary

sturlamolden sturlamolden at yahoo.no
Sat Apr 19 13:39:01 EDT 2008


On Apr 17, 4:06 pm, AlFire <spamgrinder.tryla... at gmail.com> wrote:

> Q: why function got dictionary? What it is used for?

As previously mentioned, a function has a __dict__ like (most) other
objects.

You can e.g. use it to create static variables:

int foobar()
{
   static int i = 0;
   return i++;
}

is roughly equivalent to:

def foobar():
   foobar.i += 1
   return foobar.i
foobar.i = 0










More information about the Python-list mailing list