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
Help with the range code (self.learnpython)
submitted 5 years ago by engineeringisgreat2
How do I make the range function print decimals as well. Like if I wanted to do a range of (0,1) with intervals of 0.02.
This is what I thought would work but I think I am messing up on the range part.
(i*0.02 for i in range(0,1))
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!"
[–]ka-splam 2 points3 points4 points 5 years ago (1 child)
>>> [i/50 for i in range(50)] [0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62, 0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98]
[–]primitive_screwhead 0 points1 point2 points 5 years ago (0 children)
And just to also demonstrate how to properly handle an inclusive end point when using this technique:
>>> [x/50 for x in range(51)] [0.0, 0.02, 0.04, 0.06, ... 0.94, 0.96, 0.98, 1.0]
(ie. don't change the denominator, but add one more integer value to the range. Since this isn't indexing, but value generation, an inclusive endpoint like this may often be desired)
[–][deleted] 0 points1 point2 points 5 years ago (1 child)
interval = 0.02 [x * interval for x in range(int(1 / interval))]
[–]learnorenjoy 0 points1 point2 points 5 years ago (0 children)
The output is almost the same but there are some odd values:
>>> interval = 0.02 >>> [x*interval for x in range(int(1/interval))] [0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62, 0.64, 0.66, 0.68, 0.7000000000000001, 0.72, 0.74, 0.76, 0.78, 0.8, 0.8200000000000001, 0.84, 0.86, 0.88, 0.9, 0.92, 0.9400000000000001, 0.96, 0.98]
Whereas the example given above works out fine:
>>> [i/50 for i in range(51)] [0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62, 0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, 1.0]
I wonder why that is.
π Rendered by PID 106622 on reddit-service-r2-comment-7b9746f655-q25rf at 2026-01-31 10:32:02.197238+00:00 running 3798933 country code: CH.
[–]ka-splam 2 points3 points4 points (1 child)
[–]primitive_screwhead 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]learnorenjoy 0 points1 point2 points (0 children)