如何在循环中按顺序使用数组的值?
在我的数组里,比如说,有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])
试试这段代码