N
N
NOblo2020-06-06 20:18:01
Python
NOblo, 2020-06-06 20:18:01

Why is the error not seeing the variable even though it is global?

def a():
    global b
    b="yes"
print(b)

Why print(b) fails (NameError "b" is not defined)
Even though b is global?? Why??
And how to make b really global?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-06-06
@NOblo

Because the variable is not defined in the global scopeb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question