Posts

Showing posts with the label for loop

Python3 for Loop

Image
Python For Loop for Loop:         The for loop is used to iterate over a sequence (list, tuple, string) or other iterable objects.      Iterating over a sequence  is called traversal. Syntax:           for element in sequence:                   body of for Here, elements is the variable that takes the value of the item inside the sequence on each iteration. Loop continues until we reach the last item in the sequence. Flow chart:                                        Eg:        lst=[10,20,30,40,50]        product=1        for ele in lst:               product*=ele        print("product is: {}".format(product)) output:: product is: 12000000 for more info :   https://youtu.be/yaqMSBr_NCU range() function :            We can generate a sequence of numbers using range() function. range(10) will generate numbers from 0 to 9(10 numbers). Eg:        for i in range(10):              print(i) output::     0                1                 2                3                4