str.find() always returns -1 if not found.
Can I write an expression instead of str.find() and return None if not found?
Do you mean something like this?
def find2(str, substr):
result = str.find(substr)
return result if result != -1 else None
In Python 2.4, change the last line to
if result != -1:
return result
else:
return None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With