+ 1

Python Variables

If we declare a variable in python like a=10 And later in the code if we declare change that as a=20 What will happen to the memory which is having 10

24th Jul 2018, 1:33 PM
David Paul
David Paul - avatar
3 Respuestas
+ 3
I think by doing this, you'll Overwrite the value of that variable and the previous memory location which you allocated to that variable won't change. But you'll miss the previous value.
24th Jul 2018, 2:03 PM
xXx
xXx - avatar
+ 3
the old data 10 is garbage collected if no name still refers to it
24th Jul 2018, 2:17 PM
MO ELomari
MO ELomari - avatar
+ 2
Try it out yourself with this code: a = 10 print(id(a)) a = 'not ten' print(id(a)) b = 'not ten' print(id(b)) b = 10 print(id(b)) I think the variable will stick around for some time.
24th Jul 2018, 6:03 PM
Paul
Paul - avatar