08-25-2025, 02:15 PM
I made the mistake of looking at some python the other day and I noticed that they were using the modulo to loop through a list. As in if there was a list of four items, the loop would contain something like
Code: (Select All)
items[x%4]. So that being said, what's throwing me for a loop, is that I can see how that works once 'x' becomes >= than 4, but i am stumped for when x would equal 0 to 3. Would that not be 0/4, 1/4, 2/4, and 3/4? I understand that 0/4 would have a remainder of 0, but then, to me at least, 1/4 through 3/4 would not have a whole number remainder. So how would 'items[1%4]' give you the second item in the list? To me, the remainder of 1 divided by 4 is not equal to 1. It's 0.25. If I actually type out 1%4 in my prompt, it does return 1, so apparently the computer agrees with it.

