Page 43 - Modular v1.1 Pyhton
P. 43

On running the above program, you will get the following output:





















                 Program 2: To print a pattern using for loop.




















                 On running the above program, you will get the following output:





















                 Using the range( ) Function

                 The  range( ) function  is an  in-built function  of Python.  This function  generates  a  list which
                 is a sequence type. A sequence is a succession of values bound together by a single name.

                 The range( ) function is used in the for loop to iterate over the numbers.
                 The general syntax of using the range( ) function is given below:

                    range(n): Generates a set of whole numbers starting from 0 to (n–1).
                     Example: range(6) is equivalent to [0, 1, 2, 3, 4, 5].



                                                                                  Looping Statements in Python    41
   38   39   40   41   42   43   44   45   46   47   48