工作我試圖瞭解名單和指標如何在Python工作如何列表索引在Python
所以我想這個代碼打印在列表
tokens = ["and", "of", "then", "and", "for", "and"]
for word in tokens:
word_index = tokens.index(word)
print(word_index, word)
列表中的所有物品與其對應的索引
它給了我這個輸出
0 and
1 of
2 then
0 and
4 for
0 and
所以我的問題是,爲什麼"and"
這裏有0
代替0, 3, 5
相同指數?
,我如何獲得
0 and
1 of
2 then
3 and
4 for
5 and
https://docs.python.org/3/tutorial/datastructures.html – kfx