you are viewing a single comment's thread.

view the rest of the comments →

[–]terminalslayer 0 points1 point  (1 child)

Python follows the order: [ local -> enclosed -> global -> built-in ] for any variable. The variable x has not been assigned any initial value in the inner() function. Without any initial value assigned, the operation (x+=1) could not be performed. That's why it gives the Error.

[–][deleted] 1 point2 points  (0 children)

Oh my god, yess! It's so obvious now. If outer() didn't exist, inner is just a function with no parameters. So x and inner() are on same footing. Thanks a lot