Python Forum
How Do I find Index of a character in string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Do I find Index of a character in string?
#1
how do i find index of each character,

myString = "kitti"
for char in mystring:
    print(index of each letter)
Reply
#2
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
Reply
#3
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?
Reply
#4
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'
Reply
#5
mystr = 'hello zippy'
so to find the index value of the second z?
Reply
#6
myString = "kitti"
for index, char in enumerate(mystring):
    print(index, char)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  use of escape character in re.sub and find WJSwan 1 915 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,385 Sep-27-2022, 01:38 PM
Last Post: buran
  Find and Replace numbers in String giddyhead 2 1,244 Jul-17-2022, 06:22 PM
Last Post: giddyhead
  I'm getting a String index out of range error debian77 7 2,355 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,931 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,317 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Regex: a string does not starts and ends with the same character Melcu54 5 2,430 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  [solved] unexpected character after line continuation character paul18fr 4 3,419 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  Find string between two substrings, in a stream of data xbit 1 2,162 May-09-2021, 03:32 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,427 Jan-15-2021, 04:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020