You can slice a string exactly like a list! In fact, you can think of strings as lists of characters: each character is a sequential item in the list, starting from index 0.

my_list[:2] # Grabs the first two items my_list[3:] # Grabs the fourth through last items

If your list slice includes the very first or last item in a list (or a string), the index for that item doesn’t have to be included.



Assign to dog a slice of animals from index 3 up until but not including index 6.

Assign to frog a slice of animals from index 6 until the end of the string.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?