Reason for unintuitive UnboundLocalError behaviour 2
问题 Following up on Reason for unintuitive UnboundLocalError behaviour (I will assume you've read it). Consider the following Python script: def f(): # a+=1 # 1 aa=a aa+=1 # b+='b' # 2 bb=b bb+='b' c[0]+='c' # 3 c.append('c') cc=c cc.append('c') d['d']=5 # Update 1 d['dd']=6 # Update 1 dd=d # Update 1 dd['ddd']=7 # Update 1 e.add('e') # Update 2 ee=e # Update 2 ee.add('e') # Update 2 a=1 b='b' c=['c'] d={'d':4} # Update 1 e=set(['e']) # Update 2 f() print a print b print c print d # Update 1