How can I find the remainder when dividing 2 integers

David debl2_nospammy at verizon.net
Sun Feb 26 15:24:09 EST 2006


silverburgh.meryl at gmail.com wrote:
> 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
> 
The syntax error comes from your use of the ++ operator not the modulo 
operator.  The ++ operator is not valid in python.

david lees



More information about the Python-list mailing list