For loop in python


For loop in python
For loop in python

Today we will talk about “for loop” in Python, we will see why loop is used and how loop make our work easier whenever we do some work repeatedly in such a situation we use loop. Let's say if we want to print a count from 1 to 100 and we don't have a loop, then we have to create 100 variables and initialize values ​​to all the variables, because of which the code will become very large and we also have to write a lot of coding lines. But if we use loop, then in two to three lines we can print a count from 1 to 100. Next, with the help of examples, it will see how the syntax of “for loop” works. It will also see the examples given now. Run and check in any editor or IDE of Python.


Example:
for i in range(1, 101):
    print(i, end=" ")

output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

No comments:

Post a Comment

INSTAGRAM FEED

@Python forest