Python 如何从列表中检索单词的位置?
我有一个列表,我需要检索单词的位置,到目前为止,我有,我想要打印的单词位置是seaPython 如何从列表中检索单词的位置?,python,Python,我有一个列表,我需要检索单词的位置,到目前为止,我有,我想要打印的单词位置是sea Sentence = [she , sells , sea , shells ,on , the, sea , shore] print (sentence.find(sea)) 知道我做错了什么吗?使用列表的index()功能: Sentence = ["she" , "sells" , "sea" , "shells" ,"on" , "the", "sea" , "shore"] print Senten
Sentence = [she , sells , sea , shells ,on , the, sea , shore]
print (sentence.find(sea))
知道我做错了什么吗?使用列表的index()
功能:
Sentence = ["she" , "sells" , "sea" , "shells" ,"on" , "the", "sea" , "shore"]
print Sentence.index("sea")
列表的索引是从零开始的,因此结果是
2
欢迎使用堆栈溢出!您似乎在要求某人为您编写一些代码。堆栈溢出是一个问答网站,而不是代码编写服务。请学习如何写有效的问题。老实说,这是一个非常简单的问题,有一个简单的解决方案。我不认为它应该被否决或关闭,除非它是一个复制品。