Python For Loop Examples


The value we put in the range function determines how many times we will loop. The way range works is it produces a list of numbers from zero to the value minus one. For instance, range(5) produces five values: 0, 1, 2, 3, and 4. 



Here are a few more examples: 


range(10):         0,1,2,3,4,5,6,7,8,9 

range(1,10):      1,2,3,4,5,6,7,8,9 

range(3,7):        3,4,5,6 

range(2,15,3):   2,5,8,11,14 

range(9,2,-1):    9,8,7,6,5,4,3



Post a Comment

Thank you for vising

Previous Post Next Post