0
Why s.find('') and s.find('s') returns 0 ?
s = 'star' print(s.find(''),s.find('s')) in the above code it prints 0,0 as output. why?
1 Réponse
+ 5
In python indexing starts from 0, so indexes of characters in string 'star' will be 0123.
s.find('s') return the index of 's' which is 0
s.find('') return 0 not because nothing has been found but because passing '' as a parameter just return the string itself (starting at 0)
if the string you are searching for is not in the searched string then find will return -1
s.find('1') = -1