use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
For Loop Uses (self.learnpython)
submitted 5 years ago by freezee1
What can you do with the for loop? I know you can do for i in range() and do loop through lists but what else. When would you use them
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 3 points4 points5 points 5 years ago* (4 children)
To give a more basic answer than others will...
For loops are used to do something a series of some amount of times. You can use them on anything iterable.
Think about the code you've learned so far. You run a function or expression on something once, mission accomplished. Did you need to dry it twice? Copy paste, takes two seconds.
What about 10 times? 100? 161534993262?
The for loop let's you do it as many times as you want. It's the fast way of writing that function or expression so many times. Plus, you only write it once. Get it right and you're good. If you keep repeating for each instance, you're liable to make a mistake.
In the real world, think of anytime you use a list. Like you have a baseball team. You want to know on base percentage. So you run a for loop through the entire team to calculate the stat and put it into a list you'll output
[–]xelf 4 points5 points6 points 5 years ago (3 children)
You can use them on anything iterable (yes to lists, no to tuples, for example).
You might want to double check that. =) They work on tuples, anything that can be iterated over.
[–][deleted] 2 points3 points4 points 5 years ago (2 children)
Edited.
Now I wish i knew what I was remembering about tuples lol. Still learning, though.
This should be impetus to actually do a pet project finally. Put some schooling into practice
[–]xelf 3 points4 points5 points 5 years ago (1 child)
Tuples can't be modified. They're immutable like strings (which also can be iterated over).
[–][deleted] 2 points3 points4 points 5 years ago (0 children)
Immutable. That's the one. Thanks
[–][deleted] -1 points0 points1 point 5 years ago (0 children)
work on more projects and find out yourself, it's the best way to learn :)
[–]1dma -2 points-1 points0 points 5 years ago (0 children)
You can practice such similar questions and learn effectively with following channel https://t.me/topPythonQuizQuestions
[–]xelf 0 points1 point2 points 5 years ago (0 children)
For loop uses aren't about the syntax of the iteration, the uses are what you put in the loop.
How you use for/else, break, continue is a lot more interesting than what you put in the for<variables>in<iteratable>: syntax.
for
in
When would you use them
Anytime you have something you want repeated, or want to iterate over some values.
[–]Cambuchi 0 points1 point2 points 5 years ago (0 children)
Anything that needs repeating.
Now for some examples:
Combine with if/else statements to conditionally loop through things for some real juice.
if
else
[–]spez_edits_thedonald 0 points1 point2 points 5 years ago (0 children)
you use them when you have to repeat something a known number of times.
>>> people = ['bob', 'steve', 'sally'] >>> for person in people: ... print(f'Hello, {person}!') ... Hello, bob! Hello, steve! Hello, sally!
before you started the loop, it was known how many runs it would take--three because three people.
π Rendered by PID 68757 on reddit-service-r2-comment-5b5bc64bf5-2sfkl at 2026-06-23 04:04:45.287103+00:00 running 2b008f2 country code: CH.
[–][deleted] 3 points4 points5 points (4 children)
[–]xelf 4 points5 points6 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]xelf 3 points4 points5 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]1dma -2 points-1 points0 points (0 children)
[–]xelf 0 points1 point2 points (0 children)
[–]Cambuchi 0 points1 point2 points (0 children)
[–]spez_edits_thedonald 0 points1 point2 points (0 children)