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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -