获取字母位置 [英] Get character position in alphabet

查看:185
本文介绍了获取字母位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我90%肯定有一个内置的函数,这样做。



我需要找到一个字符在字母表中的位置。因此,字符b是位置1(从0开始计算)等。是否有人知道该函数是什么?



b
$ b

编辑:我想要做的是将所有字符X的步骤数量发送回alpha投注,所以如果我有一个字符串hi gh如果我送回一步。

解决方案

它被称为 index 。例如

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

注意:在Python 3中, string.lowercase 已重命名为 string.ascii_lowercase


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')
1
>>> 

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

这篇关于获取字母位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆