Programming foundations

Stage 1 · Lesson 2 of 9

Strings and f-strings

Your first language

Text is the data you will handle most, so learn early. A string (str) is an ordered sequence of characters. Get one character by its position with s[0], take a slice (a piece) with s[1:4], and get its length with len(s).

Strings cannot be changed in place. So methods like upper(), strip(), replace() and split() return a new string and leave the original alone. That is why name.strip() on its own line seems to do nothing: you have to store the result.

Build output with f-strings, such as f"{name} is {age}", which drop values straight into the text. Joining pieces with + fails as soon as one piece is a number. split() and join() are a pair: one turns a line of text into a list, the other turns it back.

A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • The official tour: read the matching chapter after the course covers a topic

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?