Page 154 - Computer Science Class 11 With Functions
P. 154
Now, consider the following assignment statement:
>>> num1 = 100
It associates a new data object with the name num1 as shown below:
>>> id(num1)
1734046275024
>>> id(num2)
1734046084944
num1 50
1734046084944
num2 100
1734046275024
Fig 7.4: num1 and num2 refer to different data objects.
Now let us examine how a mutable object such as a list may be modified.
>>> lst1 = [30, 60, 10, 20, 50]
>>> id(lst1)
1933477279552
Fig 7.5: Variable lst1 refers to a list object (object id 1933477279552)
>>> lst2 = lst1
>>> id(lst2)
1933477279552
Note that each of lst1 and lst2 refers to the same data object.
Fig 7.6: Variables lst1 and lst2 refer to the same list object (object id 1933477279552)
Next, consider the assignment:
>>> lst1[4] = 100
>>> lst1
[30, 60, 10, 20, 100]
>>> id(lst1)
1933477279552
Note that lst1 and lst2 still refer to the same object, as further illustrated below:
>>> lst2
[30, 60, 10, 20, 100]
>>> id(lst2)
1933477279552
152 Touchpad Computer Science-XI

