AI engineering glossary · Python core

What is slicing?

Slicing: Extracting a sub-sequence with the form seq[start:stop:step]. The start is included and the stop is excluded; any part may be omitted. Slicing returns a new object and never raises an error for out-of-range bounds.

Level: beginnerTopic: Python core

Slicing: an example

'abcdef'[1:4] gives 'bcd', 'abcdef'[::2] gives 'ace', and [1, 2, 3][::-1] reverses the list to [3, 2, 1].

Related terms

More Python core terms

Where you learn it

Slicing is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.