Need to know the reason for the below observations in python 3.7
1>
"abc".count('')
returns 4 2>
"" in "abc"
returns True 3>
"abc".find("")
returns 0
I tried this and got the below results
Need to know the reason for the below observations in python 3.7
1>
"abc".count('')
returns 4 2>
"" in "abc"
returns True 3>
"abc".find("")
returns 0
I tried this and got the below results
Each character in the string "abc" is separated by an empty string. Therefore, the empty string appears between each character and at the beginning and end of the string. So, there are four empty strings in the string "abc":
"" + "a" + "" + "b" + "" + "c" + ""
You are looking for an empty string ""
.
count()
counts all possible possitions. Which are "|a|b|c|"
.
The line "" in "abc"
is looking for at least one possition.
And find()
returns the possition for the first match.