Page 110 - Computer - 8
P. 110

Lab Activity 6
                                                                                                   Experiential Learning
           To display use of various string functions in Python.
           1. Type the code as shown in the image in the Python Editor.














           2. Press the F5 key to execute the code. Sample output of the program is given below.



























          WORKING WITH LISTS

          A  List  is  a  special  type  of  variable  that  acts  like  a  container  and  can  store  multiple  values  in  it.
          The values stored in a list are called its elements and can be of the same data type or different data types.
          Each element in a list is assigned an index, starting with 0, that can be used to access it. The various
          elements of a list are enclosed within brackets ([ ]), separated by commas.


          Creating a List
          A list in Python can be created in two ways:

            1.  Assigning values to a list while writing the code

                 The various values in a list are specified, enclosed within brackets ([ ]), and separated by commas.
                 For example, list_num = [1, 2, 3, 4, 5]

            2.  Assigning values to a list while execution of program
                 The values for a list can be accepted from the user and stored in the list, using a loop and list
                functions.




              108
   105   106   107   108   109   110   111   112   113   114   115