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

  • Home
  • SEARCH
  • 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 7950565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:18:50+00:00 2026-06-04T02:18:50+00:00

Possible Duplicate: Good Primer for Python Slice Notation I first ran across it last

  • 0

Possible Duplicate:
Good Primer for Python Slice Notation

I first ran across it last night for reversing a string "Hello"[::-1] and I can’t figure out how it actually works.

"Hello"[::-1] # returns "olleH"
[1,2,3,4,5][::-1] # returns [5,4,3,2,1]
"Hello"[1:5:1] # returns "ello"
"Hello"[1:5:2] # returns "el"

My searches for “third expression in python index” have come up empty. What is this expression and how does it work. Obviously ::-1 reverses the list but I can’t figure out what the other, positive values represent.

  • 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-04T02:18:51+00:00Added an answer on June 4, 2026 at 2:18 am

    Actually the third optional argument is called step or stride.
    It’s default value is 1.

    >>> 'hello'[::] # here the value of stride is 1, means take a step of one between two indexes
    'hello'   
    
    >>> 'hello'[::2] #take a step of 2 so starting from h -->l --> o 
    'hlo'
    
    >>> 'abcdef'[::-1] #negative step actually means 'abcdef'[-1:-len('abcdef')-1:-1]
    'fedcba'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Good Primer for Python Slice Notation I have a string and I'm
Possible Duplicate: Good Primer for Python Slice Notation I've been reading over some sample
Possible Duplicate: Is this a good way to generate a string of random characters?
Possible Duplicate: Subclassing UIView to draw in Quartz Hello i am searching good example
Possible Duplicate: What’s a good IDE for Python on the Mac? Hi, I'm going
Possible Duplicate: How to get line count cheaply in Python? Good day. i have
Possible Duplicate: Is there ever a good reason to pass a string to setTimeout?
Possible Duplicate: Calling a function from a string with the function's name in Python
Possible Duplicate: Python-LDAP integration Good afternoon! I am writing a program for work that
Possible Duplicate: Is it a good idea to wrap an #include in a namespace

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.