Question Detail

COS 102 Python strings Objective Question

Question

What would be the output of len("Hello, Python!")?
Options
A 13
B 14
Correct Answer
C 15
D 12
Correct Answer

Option B is the correct answer.

Detailed Explanation

Counting each character: H(1), e(2), l(3), l(4), o(5), ,(6), (space)(7), P(8), y(9), t(10), h(11), o(12), n(13), !(14). There are 14 characters in total, including the comma, space, and exclamation mark.

Hint

Remember that len() counts *all* characters in the string, including punctuation and spaces.

Question Info