Immutable-Int
Sat 17 May 2025
title: "Immutable Int" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false
a = 12
dictionary = {
"one": a
}
a
12
dictionary
{'one': 12}
a += 9
a
21
dictionary
{'one': 12}
int is immutable, that's why you can't see the dictionary value changed
Here you are assigning to key 'a' same reference as one.
So now dictionary['one'] and a points to the same object 12.
Now when you write: a += 9 it creates a new object 21 and assigns var to this object.
Score: 5
Category: basics