Python Strings · Question 14 · Medium

Which statement about Python strings is true?

  1. s.sort() arranges the characters of s in place
  2. Methods such as upper() return a new string and leave the original unchanged
  3. s[1] = 'x' replaces the second character of s
  4. A string in single quotes has a different type from one in double quotes
Answer and explanation

Answer: B. Methods such as upper() return a new string and leave the original unchanged

Explanation: Strings are immutable, so no method or index assignment can change one in place; methods return new strings. Strings have no sort() method, and both quote styles create the same str type.

Previous: A string literal contains a tab escape and an escaped backslash. How many… · Next: A slice runs past the end of a six-letter string. What does this print?

Practise python strings

Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.

More python strings questions

More python practice

Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge