Indexing and slicing strings

12-minute lesson · module-strings-01

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Indexing and slicing strings

12-minute lesson · module-strings-01

  • Pick a single character from a string with `[i]`.
  • Take a slice with `[start:stop:step]`.
  • Use negative indices to count from the end.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Strings / Index Operator: Working with the Characters of a String

Adaptation notes. Reading rewritten in our voice. Hidden tests authored specifically for PyTutor AI.

License notes. Verify chapter-level license metadata on Runestone before copying any text verbatim. This lesson contains no verbatim quotations.