how to write program in python using for-loop

for i in range(10):

           print(i)

// i starts from 0 by default and  the loop value increase one by default

it will continue upto 9


Ans- 0,1,2,3,4,5,6,7,8,9


// if you want to print 1 to 10 using for loop

for i in range (1, 10):

           print(1)

// first argument is the intial value of loop that is 1

Ans- 1,2,3,4,5,6,7,8,9

//  if u want  to increase the value more then one ,then you have to give the third argument

for i in range (1,10,2):

print(i)

// ans-1,3,5,7,9

the first argument is for intial value 

2nd argument is for condition

third argument is for increment

Comments

Popular posts from this blog