I am trying access the bariable b
inside my funtion start
. Ive tried using a global variable and it still cannot recognize it. here is some code...
b = 1
opn_browsers = []
def start():
new = 'browser' + str(b)
b = b + 1
opn_browsers.append(new)
print(opn_browsers)
What this code should do is add browser1 to the list and print the list. then when it gets called again it should add browser2 to the list and print the list saying ['browser1', 'browser2']
. Instead it gives me this error NameError: name 'b' is not defined
. When i try adding global b into the function it yeilds this [`browser1', 'browser1']
. How can i solve this?