Recall & Review
beginner
What does the
str.upper() method do in Python?It converts all lowercase letters in a string to uppercase letters. For example,
'hello'.upper() returns 'HELLO'.Click to reveal answer
beginner
How can you remove whitespace from the start and end of a string in Python?
Use the
str.strip() method. It removes spaces, tabs, and newlines from both ends of the string. For example, ' hello '.strip() returns 'hello'.Click to reveal answer
intermediate
What is the difference between
str.replace(old, new) and str.translate()?str.replace(old, new) replaces all occurrences of a substring with another substring. str.translate() replaces characters based on a translation table, useful for multiple character replacements at once.Click to reveal answer
beginner
How do you split a string into a list of words in Python?
Use the
str.split() method without arguments. It splits the string at whitespace and returns a list of words. For example, 'a b c'.split() returns ['a', 'b', 'c'].Click to reveal answer
beginner
What does
str.join(iterable) do?It joins elements of an iterable (like a list) into a single string, inserting the original string between elements. For example,
'-'.join(['a', 'b', 'c']) returns 'a-b-c'.Click to reveal answer
Which method converts all characters in a string to lowercase?
✗ Incorrect
The
str.lower() method converts all letters to lowercase.What does
' hello '.strip() return?✗ Incorrect
The
strip() method removes spaces from both ends.How do you split the string
'one,two,three' into a list by commas?✗ Incorrect
Using
split(',') splits the string at commas.What does
'-'.join(['a', 'b', 'c']) produce?✗ Incorrect
The
join() method inserts the string between list elements.Which method replaces all occurrences of 'cat' with 'dog' in a string?
✗ Incorrect
replace() swaps all 'cat' substrings with 'dog'.Explain how to convert a string to uppercase and then remove spaces from both ends.
Think about calling one method after another on the string.
You got /3 concepts.
Describe how to split a sentence into words and then join them back with commas.
First break the string, then combine with a new separator.
You got /4 concepts.