Share your repls and programming experiences

← Back to all posts
Guide to Python : For Loop
JohnStarrs (23)

This is apart of the Guide to Python that ive been making for new users,
if you find this useful let me know.
If you need more guides check my account out as ive made a few so you can hopefully learn this amazing language of coding

Enjoy =)

An for loop is one of the few loops we have within Python.
These loops are easy to learn and code and as an added bonus they have a built in counter.
This is how it looks like :

for i in range():

Note the print can be changed to whatever function you like

Inside the () of the for loop you include the number of loops
For this example we will use 4 loops
To do this we start at 0 (because this is really 1 and not 0)
So we get :

for i in range(0,4)

You can also use the input feature to allow the user to select the amount of loops
it would look as :

x = int(input())
for i in range(0,x)

If you want we can use len() as well

y = input()
for i in range(0,len(y))

And that's the for loop for more detail look through the code as that explains the for loop as well

For more check the code in itself
or check my account for more guides to Python

theangryepicbanana (1625)

In the future, maybe try to put the explanations in the post description (possibly with some code snippets) to make it look at bit more appealing? otherwise it seems fine

JohnStarrs (23)

@theangryepicbanana kk, but isnt it more useful having it in the code itself incase they want to fork it?

theangryepicbanana (1625)

@JohnStarrs I mean maybe, but most guides I see online have more than just code in them

JohnStarrs (23)

For new programmers enjoy if you dont under stand read the grey lines with the # in front of them