code1<br>>>> def foo():<br>...     a = 1 <br>...     def bar():<br>...         b=2<br>...         print a + b<br>...     bar()<br>...     <br>... <br>>>> foo()<br>3<br><br>code2<br>>>> def foo():<br>
...     a = 1 <br>...     def bar():<br>...         b=2<br>...         a = a + b<br>...         print a<br>...     bar()<br>... <br>>>> foo()<br>Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>
  File "<stdin>", line 7, in foo<br>  File "<stdin>", line 5, in bar<br>UnboundLocalError: local variable 'a' referenced b<br><br>why code2 can not get output of 3?<br>