Learn with Yasir

Share Your Feedback

Learn Python String Methods & Formatting with MCQs.


Test your Python skills with MCQs on string methods and formatting. Great for beginners learning Python strings through hands-on practice.

๐Ÿ“ Multiple Choice Questions

๐ŸŸข Beginner

Q1. What will be the output of the following code?

name = "Alice"
print(name[1])
  1. A
  2. l
  3. i
  4. e
Answer

l

Indexing in strings starts at 0, so `name[1]` gives the second character, which is 'l'.


Q2. Which method converts a string to all uppercase letters?

  1. capitalize()
  2. upper()
  3. title()
  4. swapcase()
Answer

upper()

The `upper()` method converts all characters in a string to uppercase.


Q3. What does the `strip()` method do?

  1. Removes only leading spaces
  2. Removes only trailing spaces
  3. Removes both leading and trailing spaces
  4. Removes all spaces inside the string
Answer

Removes both leading and trailing spaces

The `strip()` method removes whitespace from both ends of the string.


Q4. What is the output of the following code?

word = "HELLO"
print(word.lower())
  1. Hello
  2. hello
  3. HELLO
  4. error
Answer

hello

The `lower()` method converts all uppercase letters in a string to lowercase.


Q5. What is the output of this code?

text = "python"
print(text.title())
  1. Python
  2. PYTHON
  3. python
  4. P y t h o n
Answer

Python


Q6. What does the `strip()` method do?

  1. Removes only leading spaces
  2. Removes only trailing spaces
  3. Removes both leading and trailing spaces
  4. Removes all spaces inside the string
Answer

Removes both leading and trailing spaces

The `strip()` method removes whitespace from both ends of the string.


Q7. What is the output of the following code?

word = "HELLO"
print(word.lower())
  1. Hello
  2. hello
  3. HELLO
  4. error
Answer

hello

The `lower()` method converts all uppercase letters in a string to lowercase.


Q8. What is the output of the following code?

text = "python"
print(text.title())
  1. Python
  2. PYTHON
  3. python
  4. P y t h o n
Answer

Python

The `title()` method capitalizes the first letter of each word in the string.


Q9. What does the `split()` method return?

  1. A single string
  2. A tuple
  3. A dictionary
  4. A list of strings
Answer

A list of strings

The `split()` method divides a string into a list based on a specified delimiter.


Q10. What will be the output of this code?

"apple,banana,grape".split(",")
  1. ['apple', 'banana', 'grape']
  2. ('apple', 'banana', 'grape')
  3. apple banana grape
  4. ["apple,banana,grape"]
Answer

['apple', 'banana', 'grape']

The `split(",")` method splits the string wherever it finds a comma and returns a list.


Q11. Which method can be used to replace all occurrences of a substring with another substring?

  1. change()
  2. substitute()
  3. switch()
  4. replace()
Answer

replace()

The `replace()` method is used to replace all occurrences of a specified substring.


๐ŸŸก Intermediate

Q1. What does the `partition()` method return?

  1. Only the substring before the separator
  2. A list of split strings
  3. A tuple of three parts
  4. A dictionary of parts
Answer

A tuple of three parts

The artition() method splits a string into three parts: before the separator, the separator itself, and after.


Q2. What is the output of the following code?

"hello world".find("o")
  1. 4
  2. 5
  3. 6
  4. -1
Answer

4

The `find()` method returns the first index of the substring "o", which is 4.


๐Ÿ”ด Advanced


๐Ÿง  Practice & Progress

Explore More Topics

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




๐Ÿง  Python Advanced

Object-Oriented Programming in Python (OOP)

More...

๐Ÿง  Modules