python - how to append item to a global list from within a procedure -


i syntax error when this:

p = [] def proc(n):     in range(0,n):         c =         global p.append(c) 

just change following:

def proc(n):     in range(0,n):         c =         p.append(c) 

the global statement can used @ top of function, , necessary when assigning global variable. if modifying mutable object not need used.

here example of correct usage:

n = 0 def set_n(i):     global n     n = 

without global statement in above function create local variable in function instead of modifying value of global variable.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -