How to get the position of a character in Python?
There are two string methods for this,
index(). The difference between the two is what happens when the search string isn't found.
'Position of a character'myString.find('s')2myString.find('x')-1myString =
'Position of a character'myString.index('s')2myString.index('x')Traceback (most recent call last): File "<stdin>", line 1, in <module>ValueError: substring not foundmyString =
From the Python manual
string.find(s, sub[, start[, end]])
Return the lowest index in s where the substring sub is found such that sub is wholly contained in
-1on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
string.index(s, sub[, start[, end]])
ValueErrorwhen the substring is not found.