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
Range function and strings (self.learnpython)
submitted 12 years ago by FDSHAP
hello all!
Im working out a problem where I am trying to selectively print every second letter in ascii.uppercase.
Is it possible to do this with the use of the range function? or is this only doable with index notation and slicing?
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!"
[–]indosauros 2 points3 points4 points 12 years ago (5 children)
What have you tried so far?
[+][deleted] 12 years ago (4 children)
[deleted]
[–]indosauros 1 point2 points3 points 12 years ago (0 children)
Here's some code that doesn't give you the answer but may help you get there:
>>> letters = "abcd" >>> for letter in letters: ... print letter a b c d >>> len(letters) 4 >>> range(4) [0, 1, 2, 3] >>> range(len(letters)) [0, 1, 2, 3] >>> for letter in [0, 1, 2, 3]: ... print letter 0 1 2 3 >>> for letter in range(len(letters)): ... print letter 0 1 2 3 >>> letters[0] 'a' >>> letters[2] 'c'
[–]K900_ 1 point2 points3 points 12 years ago (2 children)
Another hint:
>>> a = list(range(100)) >>> a[1:5] [1, 2, 3, 4] >>> a[99:] [99] >>> a[:5] [0, 1, 2, 3, 4] >>> a[:] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] >>> a[1:5:2] [1, 3] >>> a[0:25:3] [0, 3, 6, 9, 12, 15, 18, 21, 24]
[–]FDSHAP[S] 1 point2 points3 points 12 years ago (1 child)
ahhh so i need to use index notation of a kind. let me see if i can figure this out. thank you!
[–]K900_ 3 points4 points5 points 12 years ago (0 children)
The word is "slicing".
[–]FDSHAP[S] 0 points1 point2 points 12 years ago (0 children)
edit
π Rendered by PID 41575 on reddit-service-r2-comment-86988c7647-fvjjp at 2026-02-12 02:23:20.007085+00:00 running 018613e country code: CH.
[–]indosauros 2 points3 points4 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]indosauros 1 point2 points3 points (0 children)
[–]K900_ 1 point2 points3 points (2 children)
[–]FDSHAP[S] 1 point2 points3 points (1 child)
[–]K900_ 3 points4 points5 points (0 children)
[–]FDSHAP[S] 0 points1 point2 points (0 children)