variable inside class not detecting global variable in python

Solutions on MaxInterview for variable inside class not detecting global variable in python by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "variable inside class not detecting global variable in python"
Loris
10 Jul 2017
1some_global_variable
2
3class TestClass():
4    def run(self):
5        #we can access it by defining the variable as global inside the function
6        global some_global_variable 
7        for i in range(10):
8            some_global_variable = 1
9            print(some_global_variable)