#!/usr/local/bin/python3 xxx = 10 xx = 1000 class Foo: print(xxx) xx = 100 def foo(self): nonlocal xx xx = 1 print(xxx) print(xx) foo = Foo() foo.foo()