I am trying to figure out a string problem in Python. So this is from the online course Building A Search Engine and in the quiz there is a problem:
For any string s = '<any string>', which of the following always has value 0?
- (a)
s.find(s) - (b)
s.find('s') - (c)
's'.find('s') - (d)
s.find('') - (e)
s.find(s+'!!!')+1
Answer: (a), (c), (d) & (e)
And I am pretty sure about other choices except for choice (d).
I think the output should be -1 but the output is 0.
So my reasoning follows:
s is the predefined question before but '' should be considered as an empty string. So in a string to find an empty string, why not the returning is not -1 because you can not find empty in any string.
==============================================
OK, I can see my wrong thinking.
In the documentation,
Empty strings are always considered to be a substring of any other string, so "" in "abc" will return
True.
