+ 5
If i want to update the valve of global variable inside the function than how i can do this
You can take given below example to explain clearly x=10 def glb(num): #here I want to update value of x # if i write x+=20 its shows error why?? l=15 print(num,l,x) glb(10)
1 Réponse
+ 3
Because x is not defined inside the function.
You can enter:
x = 10
def glb(num):
global x
x += 20
l = 15
print(num, l, x)
Its not usually the best idea, but it'll work. What exactly are you trying to do? the variable num isnt even being used