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])
  • ๐ŸŸข A. A
  • ๐Ÿ”ต B. l
  • ๐ŸŸ  C. i
  • ๐Ÿ”ด D. 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?

  • ๐ŸŸข A. capitalize()
  • ๐Ÿ”ต B. upper()
  • ๐ŸŸ  C. title()
  • ๐Ÿ”ด D. swapcase()
Answer

upper()

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


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

  • ๐ŸŸข A. Removes only leading spaces
  • ๐Ÿ”ต B. Removes only trailing spaces
  • ๐ŸŸ  C. Removes both leading and trailing spaces
  • ๐Ÿ”ด D. 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())
  • ๐ŸŸข A. Hello
  • ๐Ÿ”ต B. hello
  • ๐ŸŸ  C. HELLO
  • ๐Ÿ”ด D. 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())
  • ๐ŸŸข A. Python
  • ๐Ÿ”ต B. PYTHON
  • ๐ŸŸ  C. python
  • ๐Ÿ”ด D. P y t h o n
Answer

Python


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

  • ๐ŸŸข A. Removes only leading spaces
  • ๐Ÿ”ต B. Removes only trailing spaces
  • ๐ŸŸ  C. Removes both leading and trailing spaces
  • ๐Ÿ”ด D. 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())
  • ๐ŸŸข A. Hello
  • ๐Ÿ”ต B. hello
  • ๐ŸŸ  C. HELLO
  • ๐Ÿ”ด D. 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())
  • ๐ŸŸข A. Python
  • ๐Ÿ”ต B. PYTHON
  • ๐ŸŸ  C. python
  • ๐Ÿ”ด D. 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?

  • ๐ŸŸข A. A single string
  • ๐Ÿ”ต B. A tuple
  • ๐ŸŸ  C. A dictionary
  • ๐Ÿ”ด D. 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(",")
  • ๐ŸŸข A. ['apple', 'banana', 'grape']
  • ๐Ÿ”ต B. ('apple', 'banana', 'grape')
  • ๐ŸŸ  C. apple banana grape
  • ๐Ÿ”ด D. ["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?

  • ๐ŸŸข A. change()
  • ๐Ÿ”ต B. substitute()
  • ๐ŸŸ  C. switch()
  • ๐Ÿ”ด D. replace()
Answer

replace()

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


๐ŸŸก Intermediate

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

  • ๐ŸŸข A. Only the substring before the separator
  • ๐Ÿ”ต B. A list of split strings
  • ๐ŸŸ  C. A tuple of three parts
  • ๐Ÿ”ด D. 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")
  • ๐ŸŸข A. 4
  • ๐Ÿ”ต B. 5
  • ๐ŸŸ  C. 6
  • ๐Ÿ”ด D. -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