python - Why does '12345'.count('') return 6 and not 5? -
>>> '12345'.count('') 6
why happen? if there 5 characters in string, why count function returning 1 more?
also, there more effective way of counting characters in string?
count
returns how many times object occurs in list, if count occurrences of ''
6 because empty string @ beginning, end, , in between each letter.
use len
function find length of string.
Comments
Post a Comment