নিচের কোডটি ক্লাস স্কোপে গ্লোবাল ভেরিয়েবল ব্যবহারের উদাহরণ দেখাচ্ছে।
উদাহরণ
class Foo(object):
bar = 2
foo = Foo()
print Foo.bar,
print foo.bar,
# setting foo.bar would not change class attribute bar
# but will create it in the instance
foo.bar = 3
print Foo.bar,
print foo.bar,
# to change class attribute access it via class
Foo.bar = 4
print Foo.bar,
print foo.bar
আউটপুট
2 2 2 3 4 3