Python Strings · Question 13 · Medium

A string literal contains a tab escape and an escaped backslash. How many characters does len() count?

print(len("a\tb\\n"))
  1. 4
  2. 5
  3. 6
  4. 7
Answer and explanation

Answer: B. 5

Explanation: \t is one tab character and \\ is one backslash character. The string is a, tab, b, backslash, n, which is 5 characters; the final n is an ordinary letter because the backslash before it was itself escaped.

Previous: Format specifiers are used inside two f-strings. What does this print? · Next: Which statement about Python strings is true?

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