[Tutor] An unknown error in my program

Lie Ryan lie.1296 at gmail.com
Sun Dec 25 12:00:53 CET 2011


On 12/25/2011 09:46 PM, Joel Goldstick wrote:
>
> You can either move the stuff at the top of your program into main, or
> you could pass the outer new
> into main as a parameter:    main(new):

the third alternative is to use the global keyword, e.g.

# declare a global named 'new'
new = 0

def increment_new():
     # tell python to use the global 'new' instead of
     # creating a local 'new'
     global new

     new += 1

print new
increment_new()
print new



More information about the Tutor mailing list