Python code for calculating number of an alphabet -
i need find number of alphabet in range of alphabets ie = 1, b=2 , c =3.... if returning value should 1
is there shorter method provided in python(inbuilt) find other declaring dictionary of 26 alphabets respected values.
please if know of such function.....
use ord()
>>> c = 'f' >>> ord(c) - ord('a') + 1 6
if want 'f' , 'f' both return 6, use lower()
>>> c = 'f' >>> ord(lower(c)) - ord('a') + 1 6
you might interested in chr()
>>> c = 'f' >>> chr(ord(c) + 1) 'g'
Comments
Post a Comment