Use external variables in for to prompt Shadows name 'count' from outer scope

there"s nothing wrong with running, but I"m confused about why I"m prompted for this, pycharm

.

Oct.19,2021

is not a big deal, pycharm is just worried about the risk that a variable name you intended to use inside the for loop ends up in global, and then you accidentally use the variable somewhere else, and an error occurs later.

the simple solution is to put the variables in the process to be used inside the function, similar to:

def print_data(data):
    print data

def main():
    data = [4, 5, 6]
    print_data(data)

main()

explain in detail: How bad is shadowing names defined in outer scopes?

Menu