Menu
Coddy logo textTech

Stepping and Negative

Lesson 14 of 19 in Coddy's Into the Past || Complete Beginner for Python Strings course.

Below you can also see a set of negative number below the positive ones.  Python is also capable of negative indexing.  What that means is you can index in reverse.  More specifically the letter e has an index of 4 and -2.   Along with negative indexing, you can use the step argument to step through a string in reverse 

letters = "abcdef"

letters[5:2:-1] --> "fed"

letters[-1:-4:-1] --> "fed"

As you can see there is more than one way to slice a string

challenge icon

Challenge

Easy

Now run the code that is given to you in the code editor and see for yourself

Try it yourself

def slice(s,start,stop,step):
    return s[start:stop:step]

All lessons in Into the Past || Complete Beginner for Python Strings