liveBook · Manning

Slicing

As explained in Learn AI-Assisted Python Programming, Second Edition

Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.

Slicing selects multiple neighboring values from a string or list by placing a starting index and an excluded ending index around a colon. section 4.3.5

Selecting part of a list

With books[1:3], Python returns the values at indexes 1 and 2, not index 3. Omitting an endpoint selects from the beginning or through the end: books[:3] and books[1:]. section 4.3.5

Building and changing words

Slicing can rebuild a string around a new character. In add_letter, word[:i] + c + word[i:] inserts a letter; change_letter uses word[:i] + c + word[i + 1:] to replace one. section 7.7.2 section 7.7.4

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Defines exclusive endpoints and omitted bounds, then applies slicing within insertion and replacement functions.
Examples
Demonstrates books[1:3], omitted bounds, and word insertion or replacement using sliced strings.
What it assumes
Assumes basic familiarity with zero-based indexing, strings, lists, loops, and functions.
What you can do after
Apply slicing in Python to extract list or string ranges and construct modified words.
How it connects
Connects indexing, strings, lists, loops, functions, and testing.

Also explained in

Compare how 16 books explain slicing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.