I have a string called x
and function called my_func
. I want to add a string to the x
, from my_func
. I tried below code but it returns an error and says "UnboundLocalError: local variable 'x' referenced before assignment"
. How can I fix it?
x = ""
def my_func():
x += "Hello World"
my_func()
print(x)