Like, I ll write a simple program for explanation.
hi=1
hii=2
def change():
hi=3
hii=4
for i in range(0,1):
change()
print(hi,hii)
Output is 1 2
But I want 3 4. How can I achieve this?
You need to use global to achieve this but keep in mind that this is not a recommended practice because of the overhead global bring with itself:
hi=1
hii=2
def change():
global hi, hii
hi=3
hii=4
for i in range(0,1):
change()
print(hi, hii)
You need to re-assign those values:
def change()
return 3, 4
hi = 1
hii = 2
print(hi, hii)
1 2
hi, hii = change()
print(hi, hii)
3 4