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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -