Page 172 - Computer Science V2.0 Class 11
P. 172

Each of the variables lst1 and lst2 refers to the same modified list object.














                             Fig 7.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 7.8: The variables list1 and list2 refer to different objects


                                                       Python Datatypes





                              Immutable Datatypes                                     Mutable Datatypes




                      Numbers                    Tuples                        Lists                     Sets



                                    Strings                                               Dictionary

                                             Fig 7.9: Mutable and immutable data types in Python


              7.3 Visualizing Execution of Python Code

              To visualize the execution of Python code, online tool PythonTutor may be used through following link
              http://www.pythontutor.com/visualize.html#mode=display


               158   Touchpad Computer Science (Ver. 2.0)-XI
   167   168   169   170   171   172   173   174   175   176   177