Page 88 - Information_Practice_Fliipbook_Class11
P. 88
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
Each of the variables lst1 and lst2 refers to the same modified list object.
Fig 4.7: Variables lst1 and lst2 refer to the same list object (object id 1933477279552)
Finally, examine the following:
>>> lst1 = [3, 4, 2, 1]
>>> id(lst1)
2353324714816
>>> id(lst2)
1933477279552
Note that assigning the variable lst1 to a new list object (indeed, it could as well be an object of some
other type) changes its object id. As expected, the assignment of the list object [3, 4, 2, 1] to the variable
lst1, did not impact the variable lst2, which continues to refer to the list [30, 60, 10, 20, 100] (object id
1933477279552).
Fig 4.8: The variables lst1 and lst2 refer to different objects
4.3 Visualising Execution of Python Code
To visualise the execution of Python code, online tool PythonTutor may be used through following link:
http://www.pythontutor.com/visualize.html#mode=display
It is a graphical interface for visualising a program's execution step by step. Fig 4.9 shows the Python Tutor interface.
To get started, you need to select the Python version in the dropdown menu for the code.
74 Touchpad Informatics Practices-XI

