---
title: "Strings: Indexing, Slicing and Length"
description: "Treating text as a sequence of characters that can be measured, indexed from zero, and cut into parts."
canonical: https://lightmysky.com/learn/computing/strings-indexing-slicing-and-length-mt_33hA050_Qz
source: https://lightmysky.com/learn/computing/strings-indexing-slicing-and-length-mt_33hA050_Qz.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Strings: Indexing, Slicing and Length

Treating text as a sequence of characters that can be measured, indexed from zero, and cut into parts.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/strings-indexing-slicing-and-length-mt_33hA050_Qz

## Ready when they can

- Get the first, last and middle characters of a string
- Take a slice and predict exactly where it starts and stops
- Use the length of a string inside a loop or a condition

## Lesson: Text by the numbers

Think of a string as a row of characters, each with its own seat number. The first character sits at seat 0, the next at 1, and so on. You write name[0] to grab the character in seat 0.

**Example.** A phone number is just text, so you can slice it. If phone holds 02079460018, then phone[0:3] copies seats 0, 1 and 2, giving 020. A slice starts at its first number and stops just before its last number.

len() counts every character: letters, digits, spaces and all. You can use that count in a loop or a test, for example to walk each seat in turn. The last seat is always one below the length, and name[-1] grabs it directly.

**Tip.** Off-by-one slips love index code, one seat too high or too low. Always check the output against the seats you meant.

**Recap.** Count seats from zero, slice from the start up to the stop, and measure with len().

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Condition-Controlled Loops](https://lightmysky.com/learn/computing/condition-controlled-loops-mt_LjxO2n3Fy6)

## Opens up

- [Lists: Many Values Under One Name](https://lightmysky.com/learn/computing/lists-many-values-under-one-name-mt_ipB6kmyK85)
- [Dynamic Programming on Two Sequences](https://lightmysky.com/learn/computing/dynamic-programming-on-two-sequences-mt_uNUgHcKKQN)
