I Think answer will be error because x is not define in whole function. and the priority of x =100 is local. so if we trying to execute this program then it will give Name error ???
No , it will not give any error.
Beacuse it is printing only the value of x i.e., 100 which is locally defined in the function.
We are not printing the x which is outside the function.
Outside the function we are calling the function only.
X+=1 will not be an issue as it considered as just a statement, which is doing nothing in the program.
But if we run that program then it will give an error (Name Error) because x isn’t define. so because python is interpreted so when it will read x+=1 then it will Name error and because of that our f1() function will be not execute
No it will not give you error as both x are different one is local variable having (x= 100)
And other is global variable having (x=+1).
Garbage collection will take of this other x (x=+1)
And function will give output as per local variable inside it.
So answer will be 100.
Do let me know if you understand this.
@dsedyoda How I can assure that the value of x in garbage collector is 100
have teams any where mentions that things
@sriv.ansh check the code it’s x= +1 (assigning) not x+=1(incrementing) , So our doubt was wrong in first place.
Ohh… .it x=+1 ohhk I got it Thanks