我正在試圖創建一個程序,它將輸入一個句子和一個單詞,並檢查該單詞的句子並返回單詞開頭的索引 即Python:獲取列表索引
sentence = "random set of words"
word = "of"
result = 9
這是我試過
sentence = (input("Enter a sentence: "))
word = (input("Enter a Word: "))
result = sentence.split()
for x in sentence:
if x == (word):
boom = enumerate(word)
print(boom)
它應該是,對於x在結果:這樣就可以得到單個單詞每次循環運行。 – pvkcse