a='1234;5'
print a.index('s')
the error is :
> "D:\Python25\pythonw.exe" "D:\zjm_code\kml\a.py"
Traceback (most recent call last):
File "D:\zjm_code\kml\a.py", line 4, in <module>
print a.index('s')
ValueError: substring not found
thanks
Try using find()
instead - this will tell you where it is in the string:
a = '1234;5'
index = a.find('s')
if index == -1:
print "Not found."
else:
print "Found at index", index
If you just want to know whether the string is in there, you can use in
:
>>> print 's' in a
False
>>> print 's' not in a
True
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