How can I find the remainder when dividing 2 integers

Diez B. Roggisch deets at nospam.web.de
Sun Feb 26 15:15:25 EST 2006


silverburgh.meryl at gmail.com schrieb:
> I have a string array:
> colors = ["#ff0000", "#00FF00", "#0000FF"]
> colorIndex = 0;
> 
> and I want to loop thru each element of colors
> 
>  for str in strings:
>  print colors[colorIndex++ % colors.length]
> 
> 
> But i get an invalid syntax error when I execute the script:
>     print colors[colorIndex++ % colors.length]
>                               ^
> SyntaxError: invalid syntax


Python doesn't have the post-decrement-operator. Also not a pre-increment.

You have to put a statement like

colorIndex += 1

in your loop.

Diez



More information about the Python-list mailing list