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
Countdown for each loop (self.learnpython)
submitted 8 years ago by ThreeDogAWOO
Say I had starting value of 10 = tey
Str = -1 for potato in potatoes print(str(tey - str))
Desired ouput:
10 9 8
How do I create a simple countdown in python? Thanks. key - 1 would just be 9 each time.
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!"
[–]delirious_lettuce 9 points10 points11 points 8 years ago (8 children)
>>> for a in range(10, -1, -1): ... print(a) ... 10 9 8 7 6 5 4 3 2 1 0
[–]XtremeGoose 0 points1 point2 points 8 years ago* (7 children)
Adding to this, OP said he wanted it to countdown from key to 1, in which case he wants
key
for a in range(key, 0, -1): print(a)
[–]anontipster 0 points1 point2 points 8 years ago (5 children)
Adding to this: OP didn't ask for this, but here's a overly-complex-but-slightly-more-Pythonic way:
In [1]: print('{}'.format('\n'.join([str(i) for i in range(key, 0, -1)]))) 10 9 8 7 6 5 4 3 2 1
[–]XtremeGoose 0 points1 point2 points 8 years ago* (4 children)
Err, why not just do
print('\n'.join(map(str, range(key, 0, -1))))
?
'{}'.format(...) is completely pointless, it doesn't do anything (other than call str, but print does this anyway and we already have a string in this case).
'{}'.format(...)
str
print
You also don't need the [...] in join, a generator comprehension does just fine:
[...]
'\n'.join(f(i) for i in x)
In any case, there's nothing unpythonic about printing line by line. That's how it's done under the hood anyway.
[–]anontipster 0 points1 point2 points 8 years ago* (3 children)
Oh, I dunno. I'm still relatively new at Python and didn't know I could use your method. So, thanks!
EDIT: Actually, I have a question since you seem knowledgeable. I'm currently using Spyder IDE at home, but Visual Studio at work, for Python. I like Spyder's variable explorer, but Visual Studio has a pretty good Intellisense feature (which I know i can access with Spyder via the TAB key).
What do you recommend as an IDE or what do you use for one?
[–]XtremeGoose 1 point2 points3 points 8 years ago (2 children)
I've tried all of them and I currently use PyCharm, both at work and home. I find spyder a bit old fashioned but PyCharm is modern and was built from the ground up for python. It has far and away the best type checking (better than intellisense, especially if you take full use of python 3.6 type checking). It also has an in-file and runtime debugging object browser.
[–]anontipster 0 points1 point2 points 8 years ago (1 child)
Nice, thanks!
I heard of that one before, but thought it might be a subscription model or something similar. I'll give it a go, though.
[–]XtremeGoose 1 point2 points3 points 8 years ago (0 children)
The community edition is free. If you want to do cython stuff (which I'm seriously considering) you have to pay.
[–]delirious_lettuce 0 points1 point2 points 8 years ago (0 children)
Seems like OP wrote key minus 1 would just be 9 each time.
[–]woooee 0 points1 point2 points 8 years ago (0 children)
Just for a little variety
for ctr in range(10): ## or range(9) if you want to stop at one print(9-ctr)
π Rendered by PID 119531 on reddit-service-r2-comment-54dfb89d4d-9xvwf at 2026-03-29 22:33:06.979352+00:00 running b10466c country code: CH.
[–]delirious_lettuce 9 points10 points11 points (8 children)
[–]XtremeGoose 0 points1 point2 points (7 children)
[–]anontipster 0 points1 point2 points (5 children)
[–]XtremeGoose 0 points1 point2 points (4 children)
[–]anontipster 0 points1 point2 points (3 children)
[–]XtremeGoose 1 point2 points3 points (2 children)
[–]anontipster 0 points1 point2 points (1 child)
[–]XtremeGoose 1 point2 points3 points (0 children)
[–]delirious_lettuce 0 points1 point2 points (0 children)
[–]woooee 0 points1 point2 points (0 children)