List slicing is one of Python’s most powerful and frequently used features — it lets you extract sublists (subsequences) efficiently using the colon : operator. Slicing creates a new list without modifying the original, making it ideal for data extraction, manipulation, and iteration.
The syntax is flexible and expressive: my_list[start:stop:step]. All parts are optional, with sensible defaults.
1. Basic Slicing Syntax
start— inclusive starting index (default: 0)stop— exclusive ending index (default: end of list)step— increment between elements (default: 1)
my_list = [10, 20, 30, 40, 50]
# Examples
print(my_list[1:3]) # [20, 30] # from index 1 to 3 (exclusive)
print(my_list[2:]) # [30, 40, 50] # from index 2 to end
print(my_list[:3]) # [10, 20, 30] # from start to index 3 (exclusive)
print(my_list[::2]) # [10, 30, 50] # every second element
print(my_list[::-1]) # [50, 40, 30, 20, 10] # reverse the list
print(my_list[-3:]) # [30, 40, 50] # last 3 elements (negative indexing)
2. Modifying Lists with Slices
Slices can also be used on the left side of assignment to replace elements.
my_list = [10, 20, 30, 40, 50]
my_list[1:3] = [99, 88] # replace index 1 and 2
print(my_list) # [10, 99, 88, 40, 50]
my_list[::2] = [0, 0, 0] # replace every second element
print(my_list) # [0, 99, 0, 40, 0]
my_list[1:4] = [] # delete elements from index 1 to 4 (exclusive)
print(my_list) # [0, 0]
3. Real-World Use Cases (2026 Examples)
Extracting recent data (time-series)
timestamps = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
recent = timestamps[-5:] # last 5 entries
print(recent) # [6, 7, 8, 9, 10]
Reversing or skipping elements
letters = list("Python")
reversed_letters = letters[::-1] # ['n', 'o', 'h', 't', 'y', 'P']
every_other = letters[::2] # ['P', 't', 'o']
Shallow copy of list
original = [1, 2, 3]
copy = original[:] # new list, independent
copy[0] = 99
print(original) # [1, 2, 3] (unchanged)
4. Common Pitfalls & Best Practices
- Out-of-range stop is safe —
my_list[10:20]returns [] - Negative step reverses —
my_list[::-1]is idiomatic reversal - Slicing always returns a new list (shallow copy) — even
my_list[:] - Assignment to slice can change length —
my_list[1:3] = [99]shortens list - For immutable sequences (strings, tuples), slicing returns same type
- Prefer negative indexing for end elements — clearer than len()-based math
Conclusion
List slicing with [start:stop:step] is one of Python’s cleanest, most versatile features — it powers everything from data extraction and reversal to shallow copies and partial updates. In 2026, master explicit start/stop/step, negative indexing, and safe bounds handling, and you'll write concise, readable, and efficient code for lists, strings, pandas Series, and NumPy arrays.
Next time you need a sublist, reversed view, or partial replacement — reach for slicing first. It's simple, powerful, and everywhere in Python.