Learn Without Walls
← Back to Module 7

Module 7 Quiz: Strings in Depth

Test your understanding with 12 questions. You need 70% (9 out of 12) to pass. Good luck!

Question 1

What is the key characteristic of Python strings that differs from lists?

  • Strings cannot be indexed
  • Strings cannot be sliced
  • Strings are immutable (cannot be changed in place)
  • Strings cannot contain numbers

Question 2

What does "Hello World".lower() return?

  • "HELLO WORLD"
  • "hello world"
  • "Hello world"
  • "Hello World"

Question 3

What does " hello ".strip() return?

  • "hello"
  • " hello"
  • "hello "
  • " hello "

Question 4

What does "banana".count("an") return?

  • 1
  • 3
  • 0
  • 2

Question 5

Given text = "Programming", what does text[0:4] return?

  • "Progr"
  • "Prog"
  • "Pro"
  • "rogr"

Question 6

How do you reverse a string in Python?

  • text.reverse()
  • reverse(text)
  • text[::-1]
  • text[-1:0]

Question 7

What does "hello".find("xyz") return?

  • -1
  • 0
  • False
  • It raises a ValueError

Question 8

What does "a,b,c,d".split(",") return?

  • "a b c d"
  • ["a,b,c,d"]
  • ("a", "b", "c", "d")
  • ["a", "b", "c", "d"]

Question 9

What does "-".join(["2024", "03", "15"]) return?

  • ["2024-", "03-", "15"]
  • "2024-03-15"
  • "-2024-03-15-"
  • "2024", "03", "15"

Question 10

What does rfind() do differently from find()?

  • It searches case-insensitively
  • It raises an error if not found
  • It searches from the right and returns the last occurrence
  • It returns all occurrences as a list

Question 11

What does the r prefix do in r"hello\nworld"?

  • Treats backslashes as literal characters (raw string)
  • Makes the string read-only
  • Reverses the string
  • Removes whitespace from the string

Question 12

Which is the most efficient way to build a string from many pieces in a loop?

  • Using += concatenation in each iteration
  • Using replace() in each iteration
  • Creating a new string variable each time
  • Appending to a list, then using "".join(list)

Quiz Results

Back to Module 7