我知道:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
print alphabet[0]
# prints a
print alphabet[25]
#prints z
以此类推,但我如何找出相反的结果,即:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
's' = alphabet[?]
""" The question mark represents that I want to know
what index the letter is in the string."""
在Python中,要获取字符串中某个字符的位置,应该是:
在javascript中,可以使用
alphabet.indexOf('a')
。你知道吗在python中,可以使用find方法:
Edit to add:正如Warren指出的那样,您也可以使用
index
,区别在于find
将返回-1
作为未找到的位置,而index
将在未找到时引发ValueError
。你知道吗在javascript中,使用
indexOf
:相关问题 更多 >
编程相关推荐