A
A
Alexander Bureyko2021-10-24 22:43:12
Python
Alexander Bureyko, 2021-10-24 22:43:12

Why does it throw an error local variable 'var' referenced before assignment?

Hello, I encountered such a problem as local variable 'var' referenced before assignment. To tell the truth, I do not understand why the code produces an error. thanks in advance!

var = 'hello'
def func():
    print(var)
    var = 'world'
func()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question