Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
8 events
when toggle format what by license comment
Mar 21, 2021 at 23:03 comment added Zoliqa It is clear that if you put some_string[::-1] you got back, the string in reverse order. However, I really don't understand what you do in this case with the other numbers? Ex.: test_string[5:1:-1] - will result a totally different way that I expect. How the first and second numbers will effect the string if the third number is "-1" ?
Jan 4, 2019 at 23:55 history rollback Endophage
Rollback to Revision 2
Jan 2, 2019 at 16:26 history edited Peter Mortensen CC BY-SA 4.0
Active reading. Removed meta information (this belongs in comments).
Jan 4, 2018 at 18:47 comment added Endophage Sure, the specific example of selecting alternate characters may not be relevant to the question, but understanding there is a 3rd parameter to slicing very much is relevant and the simple examples serve to illustrate how it works. The Python community also has a great history of educating new members in a friendly way :-)
Dec 22, 2017 at 11:03 comment added John Lockwood I think it's more likely you wanted to mention the third parameter to slice. Needing to get every other character from a string may be an important use case somewhere, but I've never had to do it. Not that there's anything wrong with wanting to show off what you know -- what's the point of knowing things if you can't do that. :) But the case for relevance to the question is overstated.
May 5, 2014 at 16:58 history edited Endophage CC BY-SA 3.0
adding more of an example. Every time I read this I think it's not clear enough.
Feb 12, 2013 at 17:59 comment added Endophage @mtahmed absolutely related to question. What if you wanted to substring by selecting alternate characters from the string? That would be my_string[::2]
Mar 20, 2012 at 0:58 history answered Endophage CC BY-SA 3.0