Can someone explain me the following :-
Suppose i have this String variable
pcalpha = 'abcdefghijklmnopqrstuvwxyz'
Writing this piece of code print(len(pcalpha))
will result in an output of an int which is equal to 26 which from my understanding means that the string has 26 characters in it.
Writing this other piece of code print(pcalpha.count(""))
shall also give the same result according to the logic am following, but it is not. Can someone tell me why is it showing 27?
The intuition is that there is a ""
after each letter and one before the first letter. So if you have 26 letters, that means you have 26 ""
plus the one at the beginning 26 + 1 = 27. For an example, let's replace "" by "-":
pcalpha = 'abcdefghijklmnopqrstuvwxyz'
print(pcalpha.replace("", "-"))
Output
-a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-
Further