Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:28:04+00:00 2026-06-01T20:28:04+00:00

Maybe someone can explain why a particular slice operation to reverse a string doesn’t

  • 0

Maybe someone can explain why a particular slice operation to reverse
a string doesn’t work. There must be something about slices I don’t
understand. Basic operation: s[start:end:step]

Given

s='abcd'

to reverse this string I can do using default values

s[::-1]

or

s[-1::-1]

Those are fine, but why doesn’t

s[-1:-1:-1]

work and give me the whole string reversed? It should start at with
the last character in the string at (-1), and the stepsize is -1. It should run
down to one before -1 i.e., index 0. Instead I get ”.

for i in xrange(3, -2, -1):
    print 's[-1:%d:-1] => ' %i,
    print s[-1:i:-1]

yields:

s[-1:3:-1] =>     # didn't expect any output
s[-1:2:-1] =>  d
s[-1:1:-1] =>  dc
s[-1:0:-1] =>  dcb
s[-1:-1:-1] =>    # shouldn't this be 'dcba'?

what am I missing here?

(I did see a lot of posting on reversing strings, but if this particular item was explained somewhere I missed it)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:28:05+00:00Added an answer on June 1, 2026 at 8:28 pm
    s[-1:-1:-1]
    

    Doesn’t work for the same reason that

    s[0:0]
    

    doesn’t give you ‘abcd’.

    When you slice, you are referring to the space between two elements, not the location of those elements. So you’re asking for the space between -1 and -1, which is ”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain to me or maybe point a link or an example of
I'm having trouble groking something in Linq - maybe someone can give me some
This is very strange, maybe someone can explain what's happening, or this is a
I'm not understanding this behavior. Maybe someone can explain to me why my current
Maybe someone can explain this behavior. Sometimes I will do an SVN update, and
Trying to understand what is going on, maybe someone can explain. Upon :HOVER I
I have the following problem, maybe someone can help me (or explain, where my
Maybe I'm a little behind the eight ball. Hopefully someone can explain this. I
Maybe this is just obvious to everyone but can someone explain where XOR (or
Can someone explain the difference between using define('SOMETHING', true); and $SOMETHING = true; And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.