Upper and Lower
Given: text = "Hello World" Print the text in all uppercase. Then print the text in all lowercase.
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"
Given: text = "Hello World" Print the text in all uppercase. Then print the text in all lowercase.
Given: sentence = "I love cats" Replace "cats" with "dogs". Print the result.
Given: data = "apple,banana,cherry" Split the string by comma to create a list. Print the second fruit (banana).
Given: words = ["Python", "is", "fun"] Join the words with a space " " to create a sentence. Print the result: "Python is fun"