Page 311 - AI Ver 1.0 Class 9
P. 311

Stop
                                                           Flowchart
            Source Code:                                                    START


            num=1
                                                                         Num 1 Sum 0
            sum=0
            while num<6:

                sum=sum+num                                                   Is      No       Display
                                                                           Num > 6?         "Sum is sum"
                num=num+1

            print("Sum is ",sum)                                                Yes
            Output:                                                    Sum = sum+num                       STOP
            Sum is 15

                                                                        Num = num+1
                    Lists in Python

            List is a collection of heterogeneous data arranged in a sequence. The values can be of any data type like string,
            integer, float, objects or even a list. Each value in a list is called an element and its position in a list is referred
            by an index number. The number of elements in a list will make the length of a list. All the elements in a list are
            separated by comma and enclosed in square brackets [ ].

            List is a mutable data type in Python as the content of the list can be added, modified or deleted by the user
            anytime throughout the code. A number of operations can be performed on the list by using a few built-in list
            functions which we will study in detail in this chapter.

            Important Features of Lists

            Based on the above definition, the list has the following important features:
               • It is mutable data type.
               • It is an ordered sequence of values.
               • Each element is separated by comma and enclosed in square brackets [ ].
               • Each value/element is accessed by an index number.

               • The values can be added, modified or deleted by the user throughout the program.
               • It stores the values of different data types.

            Creating a List

            A list is created by enclosing the values within square brackets. Each value/element is separated by a comma
            and stored under a common name. These values can be of different data types. The name follows the rules of
            naming conventions for identifiers as shown below:

                             Examples                                         Commands
               Creating an empty list                list1 = []
               Creating a list with single value     list2 = [56]
               Creating a list of friends            friends = ["Saisha", "Advika", "Arshia"]
               Creating a list of marks              marks=[92, 91, 89, 95, 93]






                                                                                Introduction to Python  309
   306   307   308   309   310   311   312   313   314   315   316