Stage 1 · Lesson 2 of 9
Strings and f-strings
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
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Beginner Python with an in-browser exercise after nearly every lesson
- CourseFreeCS50's Introduction to Programming with Python
Harvard University · Beginner
Free Harvard course whose weekly problem sets make you write real programs