Theory

Strings have many useful methods:

Case methods:

text = "Hello World"
print(text.upper()) # HELLO WORLD
print(text.lower()) # hello world

Find and replace:

message = "Hello Python"
print(message.replace("Python", "World")) # Hello World

Split and join:

words = "apple,banana,orange"
parts = words.split(",") # ["apple", "banana", "orange"]

fruits = ["a", "b", "c"]
result = "-".join(fruits) # "a-b-c"

Strip whitespace:

text = " hello "
print(text.strip()) # "hello"

Exercises in this lesson

3

Split String

Given: data = "apple,banana,cherry" Split the string by comma to create a list. Print the second fruit (banana).

Easy Points: 15
4

Join List

Given: words = ["Python", "is", "fun"] Join the words with a space " " to create a sentence. Print the result: "Python is fun"

Medium Points: 20
Solve in the playground
Next lesson: List Comprehensions →