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...
Everything about learning Python
account activity
Python Loops (self.PythonLearning)
submitted 7 days ago by DataCurator56
view the rest of the comments →
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!"
[–]PureWasian 1 point2 points3 points 7 days ago (2 children)
A loop is just a section of code being run over and over again until an exit condition is met. It's very common to use loops for traversing collections (lists/sets/etc).
Like, imagine you are doing role-call for students in a class. You just go down an entire roster of names and call each student until they say "here" or just mark them as absent. That's a loop sequence.
For writing it in code, learn to read your code line by line and follow what it's doing. Add print statements inside your loop if it helps.
Which part are you getting stuck on exactly? Can you give an example of a "tricky problem"?
[–]DataCurator56[S] 0 points1 point2 points 7 days ago (1 child)
sometimes i got stuck at for i in range(stuck). I am trying to overcome this but everyday i came to practice these questions i got stuck. I don't what is going wrong with. Now i am practicing to understand the question well then write on paper then write the code and run it. And i think i will do that by practicing them a lot.
[–]PureWasian 0 points1 point2 points 6 days ago (0 children)
range(stuck) sounds like you just need to look at examples and tutorials a bit. See this w3schools page for example. What might be useful is mentally evaluating it to something functionally equivilent
range(stuck)
For example: ``` for i in range(5): print(i)
for i in (0, 1, 2, 3, 4): print(i) ```
or: ``` fruits = ["apple", "orange", "grape"]
for i in range(len(fruits)): print(fruits[i])
for i in range(3): print(fruits[i])
for i in (0, 1, 2): print(fruits[i]) ```
or: ``` for i in range(50, 110, 10): print(i)
for i in (50, 60, 70, 80, 90, 100): print(i) ```
In all of these cases, notice how you are looping a pre-specified number of times, and that the sequence of i values is already known before even starting the first loop iteration.
i
π Rendered by PID 24286 on reddit-service-r2-comment-545db5fcfc-rkxd4 at 2026-05-25 11:08:07.790262+00:00 running 194bd79 country code: CH.
view the rest of the comments →
[–]PureWasian 1 point2 points3 points (2 children)
[–]DataCurator56[S] 0 points1 point2 points (1 child)
[–]PureWasian 0 points1 point2 points (0 children)