song_names=[“蒙面狼-海洋中的宇航员”,“比利·艾利斯-坏人”]
async def queue(ctx):
counter = 1
print(song_names)
for str in song_names:
await ctx.channel.send(counter + song_names[str])
counter += 1```
This is the error I get:
``` File "E:/.MAIN/Files/Programming/Main/main.py", line 430, in queue
await ctx.channel.send(counter + song_names[str])
TypeError: list indices must be integers or slices, not str```
循环列表时,它通常遍历每个元素。在本例中,您希望获取当前迭代元素的索引。为此,您可以在Python中使用
enumerate
:语法:
完整代码:
您已经在迭代项目sp,您可以只使用变量,而不使用
str
作为变量名:看起来你需要
enumerate()
:相关问题 更多 >
编程相关推荐