The string find
function gives -1
automatically if it does not appear in the string. So your code is doing a condition (if
statement) to check whether xlsx
is in the string.
The str.find
function is meant to find the index of the substring being in the string.
Here is an example:
>>> a = '123abc'
>>> a.find('a')
3
>>> a.find('Something that is not in the string')
-1
>>>
As mentioned in the documentation:
Return the lowest index in the string where substring sub is found within the slice s[start:end]
. Optional arguments start and end are interpreted as in slice notation. Return -1
if sub is not found.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…