Page 158 - Computer Science Class 11 Without Functions
P. 158

Clicking <Next> executes line 3 of the code, and Python displays the list lst1 and id(lst1)in the Print Output box.
        Again, clicking <Next> executes line 4 of the code, and Python displays the list lst2 and id(lst2)  in the Print
        Output box. Note that id(lst1) equals id(lst2), again confirming that the names lst1 and lst2 refer to
        the same list (Fig 7.15).






















                           Fig 7.15: Code Visualization through Python Tutor (after execution of lines 3 and 4)
        Now, clicking <Next> executes line 5, which updates the value at index 4 of list lst1 to 100. Notice that each of the
        names lst1 and lst2 refers to the same modified list object (Fig 7.16).






















                              Fig 7.16: Code Visualization through Python Tutor (after execution of line 5)
        At this stage, clicking <Next> executes line 6, associates the name lst1 and new list object (indeed, it could as well
        be an object of some other type) is created (Fig 7.17). As expected, the assignment of the list [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].





















                              Fig 7.17: Code Visualization through Python Tutor (after execution of line 6)

         156   Touchpad Computer Science-XI
   153   154   155   156   157   158   159   160   161   162   163