May-23-2018, 03:24 PM
how do i find index of each character,
myString = "kitti" for char in mystring: print(index of each letter)
How Do I find Index of a character in string?
|
May-23-2018, 03:24 PM
how do i find index of each character,
myString = "kitti" for char in mystring: print(index of each letter)
May-23-2018, 04:37 PM
It looks like you want one of these two:
https://docs.python.org/3/library/stdtyp...operations https://docs.python.org/3/library/functi...#enumerate
May-23-2018, 09:31 PM
that didnt help at all, only confused me more, didnt see what i was lookiing for. is the question that difficult or long to answer here?
if you have a string 'mystr' for example,
mystr = 'hello zippy'a string is just a list of characters, so first character is mystr[0] print(mystr[0])will give you a 'h' print(mystr[1])will give you a 'e' you can find index of the z in ziggy with: idx = mystr.index('zippy') print(mystr[idx])will give you a 'z'
May-23-2018, 11:28 PM
mystr = 'hello zippy'so to find the index value of the second z?
May-23-2018, 11:44 PM
myString = "kitti" for index, char in enumerate(mystring): print(index, char) |
|