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

时间:2016-01-21 18:20:26

标签: python

我有一个列表,我需要检索单词的位置,到目前为止,我想要打印位置的单词是海

Sentence = [she , sells , sea , shells ,on , the, sea , shore]
print (sentence.find(sea))

对我做错了什么的想法?

1 个答案:

答案 0 :(得分:1)

使用列表的index()功能:

Sentence = ["she" , "sells" , "sea" , "shells" ,"on" , "the", "sea" , "shore"]
print Sentence.index("sea")

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