This is a short one, yet very irritating. I know I can count the amount of times a string occurs within another string like this:
'banana'.count('a')
>>>3
meaning that banana
contains the letter "a"
3 times.
This is where it gets kind of weird.
My first confusion is - when I do 'foo'.count('')
, what does Python look for?
is ''
== None == anything?
It doesn't seem to be the case, but then again, what IS ''
logically speaking? And more importantly, why does
'test'.count('')
>>>5
return one more than the length of the string?
What the hell is included in a string that's always 1 higher than the amount of letters? the void?
EDIT: the '
character twice looks like one "
character. I am talking about two times '
here, to avoid confusion
EDIT2: There seems to be some confusion about how the amount of ''
happen. Refer to comments below.