如何在循环中按顺序使用数组的值?

-3 投票
1 回答
42 浏览
提问于 2025-04-14 15:33

在我的数组里,比如说,有3个值。数组是在代码中用来重复3次的,但编辑起来不太方便。

words = ["chair", "carrot", "sea"]
print ("The first word is", words[0])
print ("The second word is", words[1])
print ("The third word is", words[2])

这是一个简单的代码示例

1 个回答

-1
words = ["chair", "carrot", "sea"]

for i in range(len(words)):
    print("The", ["first", "second", "third"][i], "word is", words[i])

试试这段代码

撰写回答