Python String Methods Quiz
7 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the str.capitalize() method?

  • It capitalizes the first letter of each word in the string.
  • It returns a copy of the string with the first letter uppercase and the rest lowercase. (correct)
  • It returns a copy of the string with all letters capitalized.
  • It modifies the original string by capitalizing the first letter and lowercasing the rest.

Which of the following best describes the behavior of the str.count(s) method?

  • It returns the number of times the substring `s` appears in the string, including overlapping occurrences.
  • It returns the total number of characters in the string.
  • It returns the index of the first occurrence of the substring `s` in the string.
  • It returns the number of non-overlapping occurrences of the substring `s` in the string. (correct)

What is the purpose of the str.endswith(end) method?

  • It returns `True` if the string ends with the characters in the `end` string, and `False` otherwise. (correct)
  • It removes the characters in the `end` string from the end of the string.
  • It checks if the string contains the characters in the `end` string, regardless of their position.
  • It returns `True` if the string starts with the characters in the `end` string, and `False` otherwise.

What does the str.find(s, beg, end) method do?

<p>It returns the index of the first occurrence of the substring <code>s</code> between indices <code>beg</code> (inclusive) and <code>end</code> (exclusive) in the string, or -1 if <code>s</code> is not found in that range. (D)</p> Signup and view all the answers

What is the purpose of the str.format(*expressions) method?

<p>It returns a new string made by substituting placeholder fields in the string with the provided expressions. (D)</p> Signup and view all the answers

Which of the following is true about the str.find(s) method?

<p>It is case-sensitive and returns the index of the first occurrence of the substring <code>s</code> in the string, or -1 if <code>s</code> is not found. (D)</p> Signup and view all the answers

What is the difference between str.find(s) and str.find(s, beg)?

<p>The <code>str.find(s)</code> method returns the index of the first occurrence of <code>s</code> in the entire string, while <code>str.find(s, beg)</code> returns the index of the first occurrence of <code>s</code> starting from index <code>beg</code>. (C)</p> Signup and view all the answers

More Like This

Python String Methods Quiz
3 questions
Python String Methods Quiz
5 questions
Python String Methods Quiz
5 questions
Use Quizgecko on...
Browser
Browser