String Methods

In String Methods
parrot=“Norwegian Blue”
print len(parrot)

Why does the screen print 14 when Norwegian Blue is 12 if you start at 0 and if you count the space it still is only 13… so why does the screen display 14?

…because there are 14 characters in “Norwegian Blue”.

Why would we not count the space? It is, after all, part of the string.

len returns the length of the string. Whilst you’re correct in thinking that if we treat the string as an array of characters then N would be in index 0, why would we omit that character from the length just because it’s index is 0?

If we include zero in the sequence of integers from 0 to 13 inclusive, we have 14 integers. So it is with the characters in the string.