Scope confusion...

Gary Herron gherron at islandtraining.com
Tue Jan 21 02:02:20 EST 2003


On Monday 20 January 2003 04:59 pm, kevin at cazabon.com wrote:

Here;s another way to think of it.  This code

> def a(list = []):
>     list.append("test")
>     return list
>

is equivalent to the following

    L = []   # Create a global list

    def a(list=L): # Use L many times
        list.append("test")
        return list

This, perhaps, makes it more evident that list L is created once, and
calls to "a" append onto L.


Gary Herron






More information about the Python-list mailing list