When I run this code, it gives 0 as output But I am calling func(a). Why it is not not assigning 1 to a
a = 0
def func(x):
x = 1
func(a)
print(a)
When I run this code, it gives 0 as output But I am calling func(a). Why it is not not assigning 1 to a
a = 0
def func(x):
x = 1
func(a)
print(a)
This is because you are making a local variable in the function, ideally what you should be doing is this.
a = 0
def func():
global a
a = 1
func()
print(a)