-1 step just reverts the direction of the slice:

>>> x = "Hello World !"
>>> x[6]
'W'
>>> x[2]
'l'
>>> x[6:2:-1]
'W ol'

[6:2:-1] means give me a slice from the 6th to the 2nd item (not including), reversed.

FYI, you don't need python installed for checking the result of the code you've asked about, go to pythonanywhere and play:

PythonAnywhere is a Python development and hosting environment that displays in your web browser and runs on our servers.

Also see:

  • Explain Python's slice notation
  • Extended Slices
Answer from alecxe on Stack Overflow
๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-string-slicing
Python String Slicing - Learn By Example
April 20, 2020 - If S is a string, the expression S [ start : stop : step ] returns the portion of the string from index start to index stop, at a step size step.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-slice-string
Python slice string | DigitalOcean
August 3, 2022 - Note that Python string is immutable, ... with the start_pos index (included) and ends at end_pos index (excluded). The step parameter is used to specify the steps to take from start to end index....
๐ŸŒ
InterServer
interserver.net โ€บ home โ€บ python โ€บ how to slice strings in python: step-by-step tutorial
How to Slice Strings in Python: Step-by-Step Tutorial - Interserver Tips
April 23, 2026 - The step parameter lets you skip characters in a string. It is written as the third value in the slice: [start:stop:step]. For example, if text = "PythonProgramming", you can get every second character using:
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
September 29, 2025 - Step slicing with [::step] enables advanced operations like reversing strings ([::-1]) and skipping characters ยท Performance considerations: Slicing creates new string objects, so consider memory usage for large strings ยท AI/ML applications: Essential for text preprocessing, tokenization, and data cleaning in machine learning pipelines ยท Error handling: Python gracefully handles out-of-range indices without throwing errors, returning empty strings or partial results
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ string-slicing-in-python
String Slicing in Python - GeeksforGeeks
String slicing in Python is a way to get specific parts of a string by using start, end and step values.
Published ย  April 9, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings_slicing.asp
Python - Slicing Strings
Use negative indexes to start the slice from the end of the string: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
Real Python
realpython.com โ€บ python-strings
Strings and Character Data in Python โ€“ Real Python
December 22, 2024 - Slicing with negative indices really ... one more variant of the slicing syntax to discuss. An additional colon (:) and a third index designate a stride, also known as a step....
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings.asp
Python Strings
To check if a certain phrase or character is present in a string, we can use the keyword in. ... txt = "The best things in life are free!" if "free" in txt: print("Yes, 'free' is present.") Try it Yourself ยป ยท Learn more about If statements in our Python If...Else chapter.
๐ŸŒ
Upskillcampus
upskillcampus.com โ€บ home โ€บ slicing strings in python: a step-by-step tutorial
Slicing Strings in Python: A Step-by-Step Tutorial - Latest Insights & Guides | Career Upskilling Blogs
January 2, 2025 - It allows you to easily extract parts of a string using the syntax string [start:stop:step]. Whether you need a substring, want to skip characters, or reverse a string, slicing is an essential tool for any Python developer.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-substring-a-string-in-python
How to Substring a String in Python
January 3, 2020 - This is often called "slicing". Here is the syntax: string[start:end:step] Where, start: The starting index of the substring. The character at this index is included in the substring.
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ string-slicing-in-python
String Slicing in Python: A Complete Guide | LearnPython.com
April 15, 2024 - To select every other character, the step size should be 2. Thus, the expression [::2] selects the first character (which is p). It skips the second character and selects the third one (t). This logic continues until we reach the end. Another way of slicing a string in Python is the slice() function.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to slice strings in python?
How to Slice Strings in Python? - AskPython
August 6, 2022 - For doing so we just need to mention a step size of (-1). Let us see how that works in the example given below. #reversing string using string slicing s= "AskPython" rev_s = s[::-1] #reverse string stored into rev_s print(rev_s)
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Basic_String_Operations
Basic String Operations - Learn Python - Free Interactive Python Tutorial
This prints the characters of string from 3 to 7 skipping one character. This is extended slice syntax. The general form is [start:stop:step].
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string
Python String - GeeksforGeeks
Strings cannot be changed directly after creation. So any modification results in a new string being created using slicing or methods like replace(). ... Python provides various built-in methods to manipulate strings.
Published ย  June 11, 2026
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-substring-how-to-slice-a-string
Python Substring โ€“ How to Slice a String
July 27, 2021 - You can slice the string with steps after indicating a start-index and stop-index.
๐ŸŒ
Medium
medium.com โ€บ @sajjadhadi โ€บ python-essentials-a-fast-track-to-key-concepts-chapter-3-strings-725561046612
Python Essentials: a Fast Track to Key Concepts โ€” Chapter 3: Strings | by Sajjad Hadi | Medium
June 24, 2023 - Here, the string text is sliced with a step size of 2, starting from index 0 and ending at index 15 (exclusive). The resulting substring is "Pto rgam", which includes every second character from the original string. ... In this example, negative indexing is used to slice the string text from the 6th last character to the 1st last character (inclusive). The resulting substring is still "World". These examples demonstrate different ways to slice strings in Python ...
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ string-slicing
String Slicing (Video) โ€“ Real Python
05:35 Itโ€™s like making the same ... specify a stride in your string slice. 05:46 Itโ€™s adding an additional colon (:) and a third index designates what the stride will be. Itโ€™s also called a step....
Published ย  October 1, 2019