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.

beginnerFree

String Concatenation

Combine text strings

beginner

String Repetition

Repeat strings multiple times

beginner

String Length

Find the length of a string

beginner

String Uppercase

Convert text to uppercase

beginner

String Lowercase

Convert text to lowercase

beginner

String Replace

Replace parts of strings

beginner

String Split

Split strings into lists

beginner

Finding the Position of a Substring

Learn how to find the position of a substring within a string using Python.

intermediate

String Slicing

Extract parts of strings

intermediate

String Formatting

Format strings with variables

intermediate

String Methods - Strip

Remove whitespace from strings

beginner

String First Char

Learn how to access the first character of a string.

beginner

String Last Char

Learn how to access the last character of a string in Python.

beginner

String Title Case

Learn to capitalize the first letter of each word in a string.

beginner

String Count Chars

Learn how to count the number of times a specific character appears in a string using Python.

beginner

String Starts With

Learn how to determine if a string starts with a specific prefix.

beginner

Uppercase a word: python

Print 'python' in UPPERCASE with .upper().

beginner

String Count

Count occurrences in strings

beginner

String Startswith

Check if string starts with text

beginner

String Endswith

Check if string ends with text

beginner

String Title Case

Capitalize first letter of each word

beginner

Uppercase a word: banana

Print 'banana' in UPPERCASE with .upper().

beginner

Lowercase a word: hello world

Print 'hello world' in lowercase with .lower().

beginner

String Join

Join list items into string

beginner

Lowercase a word: openSource

Print 'openSource' in lowercase with .lower().

beginner

String Isdigit

Check if string is all digits using the isdigit() method.

beginner

String Isalpha

Check if string is all letters

beginner

String Capitalize

Capitalize first letter only

beginner

Title-case a phrase: Mountain

Print 'Mountain' in Title Case with .title().

beginner

Title-case a phrase: data science

Print 'data science' in Title Case with .title().

beginner

Capitalize the first letter: keyboard

Print 'keyboard' with only the first letter capitalized using .capitalize().

beginner

Capitalize the first letter: alabama

Print 'alabama' with only the first letter capitalized using .capitalize().

beginner

Swap the case: good morning

Print 'good morning' with its case swapped using .swapcase().

beginner

Swap the case: rocket

Print 'rocket' with its case swapped using .swapcase().

beginner

Trim the spaces: javascript

Print 'javascript' with the surrounding spaces removed using .strip().

beginner

Trim the spaces: quiet river

Print 'quiet river' with the surrounding spaces removed using .strip().

beginner

Length of a string: elephant

Print the number of characters in 'elephant' with len().

beginner

Length of a string: compiler

Print the number of characters in 'compiler' with len().

beginner

Count a letter: byte stream

Print how many times 'a' appears in 'byte stream' using .count().

beginner

Count a letter: north star

Print how many times 'a' appears in 'north star' using .count().

beginner

Reverse a string: velocity

Print 'velocity' reversed using slicing [::-1].

beginner

Reverse a string: cinnamon

Print 'cinnamon' reversed using slicing [::-1].

beginner

Replace a letter: green field

In 'green field', replace every 'a' with 'o' and print the result.

beginner

Replace a letter: tangerine

In 'tangerine', replace every 'a' with 'o' and print the result.

beginner

First word of a phrase: python

Print the first word of 'python' (split on spaces).

beginner

First word of a phrase: banana

Print the first word of 'banana' (split on spaces).

beginner

First three letters: hello world

Print the first three characters of 'hello world' using slicing.

beginner

First three letters: openSource

Print the first three characters of 'openSource' using slicing.

beginner

Count the vowels: Mountain

Count the vowels (a, e, i, o, u) in 'Mountain' and print the total.

beginner

Count the vowels: data science

Count the vowels (a, e, i, o, u) in 'data science' and print the total.