LearnFrenzy
Sign in Take a free test

Strings · Predict the Output · Question 15

Escape sequences and raw strings Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What is the output of the following Python program?

main.py
print(len("a\nb"), len(r"a\nb"), "C:\\new".count("\\"), len("\t"))
  • A 3 4 1 1 Correct
  • B 4 4 2 2
  • C 3 3 1 1
  • D 4 3 2 1
Correct Answer: Option A

"\n" is one character, but in a raw string it is two (\ and n). "\" is one backslash, so "C:\new" contains one. "\t" is a single tab.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links