Strings: Interactive Python Lessons
Slice, format, and process text with Python string exercises: f-strings, methods, and real-world text manipulation challenges.
50 lessons in this topic — 1 free to start. Every lesson runs real Python in your browser with instant feedback.
String Concatenation
Combine text strings
String Repetition
Repeat strings multiple times
String Length
Find the length of a string
String Uppercase
Convert text to uppercase
String Lowercase
Convert text to lowercase
String Replace
Replace parts of strings
String Split
Split strings into lists
Finding the Position of a Substring
Learn how to find the position of a substring within a string using Python.
String Slicing
Extract parts of strings
String Formatting
Format strings with variables
String Methods - Strip
Remove whitespace from strings
String First Char
Learn how to access the first character of a string.
String Last Char
Learn how to access the last character of a string in Python.
String Title Case
Learn to capitalize the first letter of each word in a string.
String Count Chars
Learn how to count the number of times a specific character appears in a string using Python.
String Starts With
Learn how to determine if a string starts with a specific prefix.
Uppercase a word: python
Print 'python' in UPPERCASE with .upper().
String Count
Count occurrences in strings
String Startswith
Check if string starts with text
String Endswith
Check if string ends with text
String Title Case
Capitalize first letter of each word
Uppercase a word: banana
Print 'banana' in UPPERCASE with .upper().
Lowercase a word: hello world
Print 'hello world' in lowercase with .lower().
String Join
Join list items into string
Lowercase a word: openSource
Print 'openSource' in lowercase with .lower().
String Isdigit
Check if string is all digits using the isdigit() method.
String Isalpha
Check if string is all letters
String Capitalize
Capitalize first letter only
Title-case a phrase: Mountain
Print 'Mountain' in Title Case with .title().
Title-case a phrase: data science
Print 'data science' in Title Case with .title().
Capitalize the first letter: keyboard
Print 'keyboard' with only the first letter capitalized using .capitalize().
Capitalize the first letter: alabama
Print 'alabama' with only the first letter capitalized using .capitalize().
Swap the case: good morning
Print 'good morning' with its case swapped using .swapcase().
Swap the case: rocket
Print 'rocket' with its case swapped using .swapcase().
Trim the spaces: javascript
Print 'javascript' with the surrounding spaces removed using .strip().
Trim the spaces: quiet river
Print 'quiet river' with the surrounding spaces removed using .strip().
Length of a string: elephant
Print the number of characters in 'elephant' with len().
Length of a string: compiler
Print the number of characters in 'compiler' with len().
Count a letter: byte stream
Print how many times 'a' appears in 'byte stream' using .count().
Count a letter: north star
Print how many times 'a' appears in 'north star' using .count().
Reverse a string: velocity
Print 'velocity' reversed using slicing [::-1].
Reverse a string: cinnamon
Print 'cinnamon' reversed using slicing [::-1].
Replace a letter: green field
In 'green field', replace every 'a' with 'o' and print the result.
Replace a letter: tangerine
In 'tangerine', replace every 'a' with 'o' and print the result.
First word of a phrase: python
Print the first word of 'python' (split on spaces).
First word of a phrase: banana
Print the first word of 'banana' (split on spaces).
First three letters: hello world
Print the first three characters of 'hello world' using slicing.
First three letters: openSource
Print the first three characters of 'openSource' using slicing.
Count the vowels: Mountain
Count the vowels (a, e, i, o, u) in 'Mountain' and print the total.
Count the vowels: data science
Count the vowels (a, e, i, o, u) in 'data science' and print the total.