Sami
Sami

Reputation: 21

Identify the index of something in Python 3

I'm new to python, and I'm wondering if there is a way to identify the index position of something in python?

For example, if I have a string consisting of the alphabet a-z, and I ask the user to input a letter, is there a way I can make the program identify that the letter "f" has the index 5 in the alphabet string?

Upvotes: 0

Views: 6653

Answers (2)

fraxel
fraxel

Reputation: 35279

>>> 'asdfsadg'.index('f')
3

Upvotes: 5

ziad-saab
ziad-saab

Reputation: 20249

Do you mean like this?

alpha = "abcdefghijkl..."
alpha.index("f")

Upvotes: 6

Related Questions