Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从列表中检索单词的位置?_Python - Fatal编程技术网

Python 如何从列表中检索单词的位置?

Python 如何从列表中检索单词的位置?,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

我有一个列表,我需要检索单词的位置,到目前为止,我有,我想要打印的单词位置是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 Sentence.index("sea")

列表的索引是从零开始的,因此结果是
2

欢迎使用堆栈溢出!您似乎在要求某人为您编写一些代码。堆栈溢出是一个问答网站,而不是代码编写服务。请学习如何写有效的问题。老实说,这是一个非常简单的问题,有一个简单的解决方案。我不认为它应该被否决或关闭,除非它是一个复制品。