qwerty qwerty - 7 months ago 106
Python Question

Get character position in alphabet

I'm 90% sure there is a built in function that does this.

I need to find the position of a character in an alphabet. So the character "b" is position 1 (counting from 0), etc. Does anyone know what the function is called?

Thanks in advance!

EDIT: What i'm trying to do is to send all the characters X amount of "steps" back in the alpha bet, so if i have a string with "hi" it would be "gh" if i sent it back one step. There might be a better way of doing it, any tips?


It is called index. For e.g.

>>> import string
>>> string.lowercase.index('b')

Note: in Python 3, string.lowercase has been renamed to string.ascii_lowercase.