Page 259 - Ai_V1.0_Class9
P. 259

• index(): It returns the index number of the value given in the function. For example,
                    city=["Delhi", "Mumbai", "Kolkata", "Chennai"]

                   print (city.index("Kolkata"))
                    Output: 2
                    print (city.index("Pune"))
                    Output: ValueError: 'Pune' is not in list
                    It returns ValueError exception if the value is not found in the list.

                    • count(): This function counts the number of occurrences of the specified value in the given list. If the value
                   doesn't exist, then the function returns 0. For example,

                    marks = [56, 67, 45, 78, 56, 78, 12]
                   marks.count(78)
                    Output: 2
                   marks.count(10) # 10 does not exist in the list.
                    Output: 0




                          At a Glance


                       • A program is written in any programming language which the computer can understand and execute.
                       • An algorithm is a step-by-step approach to identify and solve a problem in a finite time.
                       • A flowchart is a graphical representation of an algorithm.
                       • Keywords in Python are predefined and reserved words with special meanings and purposes.
                       • Identifiers are the user defined names of variables, list, dictionary, tuples, classes, etc.

                       • Variable is a name given to a memory location to hold a specific value.
                       • Data types specify the kind of a value a variable can store. It helps us to identify the kind of operation that can be
                       performed on that specific data type.
                       • Operators are special symbols used to perform mathematical, logical and relational operations on variables and values.
                       • Comments are used to increase the readability of the code.
                       • The print() function is used to print an output on the screen.

                       • A step-by-step process of execution of code is called sequential flow of control.
                       • Selection flow of control is achieved through conditional statements.
                       • The range( ) function is an inbuilt function that is used to generate a sequence of values between the specified range.
                       • The elements of a list can be accessed by using its index number starts with 0 (zero).



















                                                                                        Introduction to Python  257
   254   255   256   257   258   259   260   261   262   263   264