>From the language lawyers section of python doc.s :- "If a name is assigned to anywhere in a code block (even in unreachable code), and is not mentioned in a global statement in that code block, then it refers to a local name throughout that code block." Try:- def run(): a = 1 def run2(b): global a print a a = b run2(2) print a run()