Ask coding questions

← Back to all posts
For loop list indexing
daSeaTurtle

So I want to index my list with a for loop. But I want it so when the list index is out of range it restarts indexing from 0.
this is my code so far:

(this is discord.py, if you spot any other mistakes pls let me know)

So does anyone know how to do it?

Answered by Geocube101 [earned 5 cycles]
View Answer
Voters
daSeaTurtle
Comments
hotnewtop
Geocube101

Try using the modulo "%" operator

daSeaTurtle

@Geocube101 Thank you this worked!