Test your Python skills with MCQs on string methods and formatting. Great for beginners learning Python strings through hands-on practice.
name = "Alice"
print(name[1])
l
Indexing in strings starts at 0, so `name[1]` gives the second character, which is 'l'.
upper()
The `upper()` method converts all characters in a string to uppercase.
Removes both leading and trailing spaces
The `strip()` method removes whitespace from both ends of the string.
word = "HELLO"
print(word.lower())
hello
The `lower()` method converts all uppercase letters in a string to lowercase.
text = "python"
print(text.title())
Python
Removes both leading and trailing spaces
The `strip()` method removes whitespace from both ends of the string.
word = "HELLO"
print(word.lower())
hello
The `lower()` method converts all uppercase letters in a string to lowercase.
text = "python"
print(text.title())
Python
The `title()` method capitalizes the first letter of each word in the string.
A list of strings
The `split()` method divides a string into a list based on a specified delimiter.
"apple,banana,grape".split(",")
['apple', 'banana', 'grape']
The `split(",")` method splits the string wherever it finds a comma and returns a list.
replace()
The `replace()` method is used to replace all occurrences of a specified substring.
A tuple of three parts
The artition() method splits a string into three parts: before the separator, the separator itself, and after.
"hello world".find("o")
4
The `find()` method returns the first index of the substring "o", which is 4.