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 8018599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:09:51+00:00 2026-06-04T21:09:51+00:00

Normally to reverse a list one should do the following: >>>>l = [1, 2,

  • 0

Normally to reverse a list one should do the following:

>>>>l = [1, 2, 3, 4, 5]
>>>>l[::-1]  
[5, 4, 3, 2, 1]

But isn’t the exact syntax like this:

list[<start>:<end>:<stop>]

and if I don’t give an optional parameter the defaults are as follows(Correct me if I am wrong:

<start> = 0(Beginning of list)
<end>   = 5(Length of list)
<step>  = 1

So if I give the optional parameters, it should in effect produce the same result:

>>>>l[0:5:-1]
>>>>[]

But instead I get an empty list(and I know why this happening), but what are the default values being taken by python in the 1st case?It should take 0 and 5 as default and produce nothing, or is [::-1] different from list[start:end:stop]

  • 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-04T21:09:52+00:00Added an answer on June 4, 2026 at 9:09 pm

    l[::-1] is equivalent to l[slice(None,None,-1)], where slice([start], stop[, step]) returns a slice object.
    Consider the following:

    >>> slice(None,None,-1).indices(5)
    (4, -1, -1)
    >>> slice(None,None,1).indices(5)
    (0, 5, 1)
    

    This is the exact behaviour you see when using the extended indexing syntax to access your list, i.e l[start:stop:step].

    >>> l[::-1]
    [5, 4, 3, 2, 1]
    >>> l[slice(None,None,-1)]
    [5, 4, 3, 2, 1]
    

    … but what are the default values being taken by python in the 1st case?

    The values for start/stop (if not provided) is based on the number if indices (length of list) as well as the value of step. Specifically, see the CPython source for the slice object (Objects/sliceobject.c)

    if (r->start == Py_None) {
        *start = *step < 0 ? length-1 : 0;
    } else {
        /* .... */
    }
    
    if (r->stop == Py_None) {
        *stop = *step < 0 ? -1 : length;
    } else {
        /* .... */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally this would be something like: glutAddMenuEntry(-, <opid>); But it doesn't work. After looking
Normally validation of simple email is: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ This will validate email like test@test.com But
Normally, RadioButtonGroup is aligned vertically like this: O option 1 O option 2 O
In OpenGL, one often writes code like this: glPushMatrix(); // modify the current matrix
I would like to use the following code in C# but I just can't
Normally when you iterate through a mysql result you do something like this: while
Normally, this would be incredibly easy with tables, but everyone says tables are bad
Normally, this is a trivial question that can be answered with a simple search
Normally it is possible to apply data validation in excel through vba but i
Normally i'm parsing JSON feeds like (EXAMPLE) ; { AppStore: [ { Application: Game,

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.