Skip to content
beginner

Slicing and Indexing in Python: Lists, Strings, and More

You know how to build a list. Now comes the part that makes lists genuinely useful: pulling out exactly the items you need. Indexing grabs one item by…

Published 2026-09-05Updated 2026-09-128 min read
Detailed close-up of lush green leaves and tree branches in a natural setting.
Detailed close-up of lush green leaves and tree branches in a natural setting. Photo by Shibmohan prasad Negi on Pexels.

You know how to build a list. Now comes the part that makes lists genuinely useful: pulling out exactly the items you need. Indexing grabs one item by position. Slicing grabs a whole range in a single step. Together, they turn a pile of data into something you can actually work with—the difference between reading everything and reading what matters.

Why Indexing and Slicing Matter

Imagine you have a list of customer names and you need the last three who signed up. Or a sentence where you want just the first word. Or a week of sales figures where you need every other day for a quick scan.

Without indexing and slicing, you would write loops for all of that. With them, you write one short expression.

These skills work across lists, strings, and tuples because Python treats them all as sequences—ordered collections where each item has a position. If you have worked with lists in Python before, you already know how to create them and access individual items. This tutorial builds on that foundation and shows you how to grab any piece of any sequence with precision.

Indexing: Grabbing One Item by Position

Indexing is how you pull a single item out of a sequence using square brackets and a number.

Python uses zero-based indexing. That means the first item lives at position 0, not position 1. This trips up nearly every beginner at least once, so let's make it stick with a tiny example:

colors = ["red", "green", "blue", "yellow"]

print(colors[0])
print(colors[2])
red
blue

The first item is at index 0, the second at index 1, and so on. If you want the third item, you ask for index 2.

Python also lets you count from the end using negative indexes. The last item is at index -1, the second-to-last at -2, and so on:

colors = ["red", "green", "blue", "yellow"]

print(colors[-1])
print(colors[-2])
yellow
blue

Negative indexing is one of those features you will reach for constantly once you know it exists. Pulling the last item from a list is my_list[-1]—no need to know how long the list is.

One warning: if you index past the end of a sequence, Python raises an IndexError. Ask for colors[10] on a four-item list and the program stops with a traceback. Slicing, as you are about to see, is far more forgiving.

Knowledge check

Check your understanding

Answer this question before you continue.

What does this code print?
Output Prediction

Focus: Use zero-based indexing to predict which item a list index returns.

colors = ["red", "green", "blue", "yellow"]
print(colors[2])

Slicing: Grabbing a Range of Items

A two-column comparison shows indexing with fruits[2] selecting only the item at position 2, while slicing with fruits[1:3] highlights positions 1 and 2 and leaves position 3 outside the highlighted range; the sequence cells are labeled with zero-based indexes.
Indexing selects one position; slicing includes the start position and stops before the stop position.

Slicing is indexing's bigger sibling. Instead of one item, you get a range of items in one step.

The syntax looks like this:

sequence[start:stop]

The start index is included. The stop index is exclusive—Python stops just before it. This is the single most important rule in slicing, and forgetting it causes most beginner confusion.

Here is what it looks like on a list:

fruits = ["apple", "banana", "cherry", "date", "elderberry"]

print(fruits[1:3])
['banana', 'cherry']

Index 1 is "banana", which gets included. Index 3 is "date", which does not. You asked for positions 1 through 3, and Python gave you 1 and 2.

You can omit either side of the colon. Omitting start begins at the beginning. Omitting stop runs to the end:

fruits = ["apple", "banana", "cherry", "date", "elderberry"]

print(fruits[:2])
print(fruits[3:])
['apple', 'banana']
['date', 'elderberry']

Slicing returns a new sequence and never changes the original. Your fruits list stays exactly as it was, which makes slicing a safe way to explore data without worrying about side effects.

Knowledge check

Check your understanding

Answer this question before you continue.

What does this code print?
Output Prediction

Focus: Predict the items returned by a slice with an exclusive stop index.

fruits = ["apple", "banana", "cherry", "date", "elderberry"]
print(fruits[1:3])

Negative Indexes and the Step Value

Negative indexes work inside slices too, and they make common tasks almost effortless.

Want the last three items of a list? This is the slice you will memorize:

scores = [88, 92, 79, 85, 91, 96]

print(scores[-3:])
[85, 91, 96]

The slice starts at the third item from the end and runs to the end. No math required.

Slices also accept a third value: step. The step controls how many items Python skips between selections. A step of 2 grabs every second item:

numbers = [10, 20, 30, 40, 50, 60]

print(numbers[::2])
[10, 30, 50]

The full slice syntax is start:stop:step. When you write numbers[::2], you are saying: start at the beginning, go to the end, and take every second item.

The step value can also be negative, which reverses direction. The classic trick is reversing a sequence with [::-1]:

word = "python"

print(word[::-1])
nohtyp

A step of -1 walks backward through the sequence, so you get a reversed copy. This works on lists, strings, and tuples alike.

Common mistake: A negative step reverses the direction of the slice. If you combine it with start and stop values, those values are now interpreted from the end. Keep your early reverse slices simple—[::-1] is all you need most of the time.

Knowledge check

Check your understanding

Answer this question before you continue.

What does this code print?
Output Prediction

Focus: Use a step value to select every other item from a sequence.

numbers = [10, 20, 30, 40, 50, 60]
print(numbers[::2])

Slicing Strings and Tuples

Here is the payoff for learning slicing on lists: the exact same rules apply to strings and tuples. Learn it once, use it everywhere.

The same square-bracket position syntax works across all three sequence types. A plain number grabs one item. A colon grabs a range. Watch how indexing behaves on a string and a tuple:

message = "Hello, Python learner!"
coordinates = (10, 20, 30, 40, 50)

print(message[0])
print(coordinates[2])
H
30

Index 0 of the string is its first character. Index 2 of the tuple is its third item. Same rule, different sequence.

Now add the colon, and you are slicing. Strings slice the same way lists do. Grabbing a substring is just slicing:

message = "Hello, Python learner!"

print(message[7:13])
print(message[-8:])
Python
learner!

Tuples slice too, and the result is still a tuple:

coordinates = (10, 20, 30, 40, 50)

print(coordinates[1:4])
(20, 30, 40)

Strings and tuples are immutable, meaning you cannot change them after creation. Slicing is the safe way to get a piece of them because it creates a new object rather than trying to modify the original.

Knowledge check

Check your understanding

Answer this question before you continue.

What is the result of slicing this tuple?
Single Choice

Focus: Recognize that slicing a tuple returns another tuple.

coordinates = (10, 20, 30, 40, 50)
coordinates[1:4]

Common Beginner Mistakes

Every Python developer has hit these walls. Here is how to recognize and fix them quickly.

Forgetting that stop is exclusive. You ask for my_list[1:3] expecting three items and get two. The item at the stop index is never included. If you want items at positions 1, 2, and 3, write my_list[1:4].

Confusing indexing with slicing. One bracket with a number is indexing: my_list[2]. A colon inside the brackets means slicing: my_list[2:5]. They look similar and behave very differently.

Expecting an error when slicing past the end. Indexing past the end raises an IndexError. Slicing past the end does not—Python simply returns everything available:

colors = ["red", "green", "blue"]

print(colors[10:])
[]

No crash, just an empty list. Slicing is forgiving; indexing is strict.

Using a negative step without realizing it reverses direction. A step of -1 walks backward. If your slice comes back empty or reversed when you expected forward motion, check whether your step is negative.

Practice: Slice Your Way Through Real Data

Time to make this stick. Here is a small dataset representing a week of sales:

sales = [120, 85, 150, 95, 210, 175, 140]

Using what you have learned, write code that:

  1. Pulls the first three days of sales.
  2. Pulls the last two days of sales.
  3. Pulls every other day's sales.

Try it yourself before peeking at the solution:

sales = [120, 85, 150, 95, 210, 175, 140]

print(sales[:3])
print(sales[-2:])
print(sales[::2])
[120, 85, 150]
[175, 140]
[120, 150, 210, 140]

If your output matches, you have the core mechanism down. If not, trace through each slice slowly. Write the indexes above the list values and walk through what Python sees.

The Mental Model That Carries You Forward

Indexing grabs one item. Slicing grabs a range. The stop index is always exclusive. Negative indexes count from the end. A step of -1 reverses direction.

That is the whole foundation. These same skills carry directly into reading files, cleaning data, and building real projects—anywhere you need to pull a specific piece out of a larger collection. When you are ready to push further, the data structures practice exercises will give you more reps, and file I/O will show you how slicing helps you process real data from disk.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

What does this code print?
Question 1 of 2Output Prediction

Focus: Use a step of -1 to reverse a sequence with slicing.

word = "python"
print(word[::-1])
Which statement correctly compares these two expressions for the three-item list `colors = ["red", "green", "blue"]`?
Question 2 of 2Misconception Check

Focus: Distinguish forgiving out-of-range slicing from strict out-of-range indexing.

References

  1. Slicing and Indexing in Python – Explained with Exampleswww.freecodecamp.org
  2. Python Program to Slice Listswww.programiz.com
  3. Python list slicing (with examples) - Python Morselswww.pythonmorsels.com
8sources checked
8source domains
5searches run

Research updated Sep 5, 2026

Practical resource

Want a more structured Python path?

Use the Python Starter Pack to turn scattered tutorials into a focused practice path.

View the bundle
Coming soon

Python Starter Pack

A compact LearnPyFast PDF pack covering what Python is, installation, your first program, running Python code, and Python versions.

$9
PDF BundleTopic PackPythonBeginner
  • 5 curated chapters
  • Enhanced PDF edition with bundle-only learning guidance
  • Offline-friendly format for focused review
  • Source article links for future online updates

Coming soon

Free Python bundle

Get the LearnPyFast Python Starter Bundle

A focused collection of beginner-friendly Python resources to help you move from setup to building practical projects.

You’ll receive the bundle by email. You can unsubscribe anytime.

No spam. You can unsubscribe anytime. See our Privacy policy.

Related sites

Continue beyond Python

Explore related Worldmonger sites when you want to move from Python basics into JavaScript or LLM application building.

JavaScript tutorialstutorial

LearnJSFast

Beginner-friendly JavaScript tutorials for practical web development and self-taught developers.

JavaScriptFrontendWeb development
Visit LearnJSFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related tutorials

Continue with nearby Python topics and beginner-friendly explanations.

Vibrant autumn landscape featuring a solitary oak tree in a green field under a cloudy sky.
beginner
10 min read

Basic File I/O in Python

A Python program that never touches a file forgets everything the moment it exits. File I/O is how your code keeps data after the run ends—saving notes,…

Read tutorial
Teacher conducting a lesson with engaged students in a modern classroom setting.
beginner
11 min read

How to Count Words in Python

Counting words in Python sounds trivial until you try it on real text. The moment your sentence contains a comma, a capital letter, or an ellipsis, the…

Read tutorial