Differences between revisions 1 and 2
Revision 1 as of 2012-04-24 05:52:28
Size: 1028
Editor: 58-7-169-58
Comment:
Revision 2 as of 2012-04-24 06:01:32
Size: 1025
Editor: 58-7-169-58
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
## def fun(): def fun():

Asking for Help: ...

The following puzzles me: Both a and b are globals. Both are assigned an initial value in fun(). But b is considered unassigned in fun1().

def fun():

  • global a,b a = [0]*1 b = 0 fun1()

def fun1():

  • a[0] += 1 print('a[0]: ', a[0]) b += 1 print('b: ', b)

fun()

  • b += 1

UnboundLocalError: local variable 'b' referenced before assignment

When answering questions, add the CategoryAskingForHelpAnswered category when saving the page. This will move the link to this page from the questions section to the answers section on the Asking for Help page.


CategoryAskingForHelp

Asking for Help/Why is my global not assigned? (last edited 2012-04-24 20:58:40 by PaulBoddie)

Unable to edit the page? See the FrontPage for instructions.