这是我的代码:
sentence = input("Give me a sentence ")
word = input("What word would you like to find ")
sentence_split = sentence.split()
if word in sentence_split:
print("have found",word,)
print("The word comes in the position" )
else:
print("error have not found",word)
wordfound = (sentence_split.index(word)+1)
print(wordfound)
我能得到字符串中第一个单词出现的索引。我怎样才能得到所有的事件?
使用^{} :
对于
word = "this"
和sentence = "this is a sentence this this"
这将产生输出:相关问题 更多 >
编程相关推荐