Module 3: Python Strings

Beginner 10 chapters

30. Introduction to Strings

Get started with Python strings: how to create them, use quotes and escape characters, join and repeat them, read single characters, and understand that strings cannot be changed.

Beginner25 min

31. String Indexing

Learn how every character in a string has a position number, how to read characters with positive and negative indexes, and how to avoid IndexError.

Beginner20 min

32. String Slicing

Learn how to cut parts out of a string with start:stop:step slices, use negative numbers, and reverse text with [::-1].

Beginner25 min

33. String Concatenation

Learn to join strings with +, repeat them with *, build them with +=, and combine many strings with join().

Beginner20 min

34. String Formatting

Learn how to build text from templates with str.format() and the percent operator, and how to control width, alignment and decimal places.

Beginner25 min

35. f-Strings

Learn f-strings, the modern way to build text in Python by placing values and expressions inside curly braces, and format numbers, widths and alignment with simple format specs.

Beginner25 min

36. String Methods

Explore the most useful string methods in Python: changing case, trimming, searching, replacing, splitting, joining and testing the content of text.

Beginner30 min

37. Escape Characters

Learn escape characters such as newline, tab, backslash and quotes, plus raw strings and Unicode escapes, so you can put special characters inside Python strings.

Beginner20 min

38. Multiline Strings

Learn how to write strings that span several lines with triple quotes, how indentation and line breaks behave, and how to tidy multiline text with dedent, strip and splitlines.

Beginner20 min

39. String Immutability

Learn why Python strings cannot be changed in place, what error you get when you try, and how to build new strings with slicing, replace() and join() instead.

Beginner20 min

Take the module test