a = ['s','j','d','f']
string_complete = ''
for s in a:
string_complete += s
print(string_complete)
print(id(string_complete))
This code outputs
S 4528461808 Sj 4578482160 Sjd 4578484144 Sjdf 4578483056
which is expected as everytime string_complete is updated it goes to new address But when I comment out print line, results are unexpected
string_complete = ''
for s in a:
string_complete += s
print(id(string_complete))
#print(string_complete)
4528461808 4590072304 4590072304 4590072304
Is this coincidence? I have tried multiple times still getting the last three addresses same? What is going on here ?