-4

I am taking a codeacademy beginners course in Python. What does the character "%" mean in this expression - 45 % 12? I am using Python 2.7.5. i have looked at various references, and cannot find it.

2 Answers2

0

It's the modulus operator - 45 divided by 12 = 3 and 9/12. In short, it would return 9.

It's a neat way of looping up to a certain count

eg the following will run on alternate rows...

for i in range[0,100]
    if i % 2 == 0:
        #Even row
    else:
        #Odd row
Basic
  • 26,321
  • 24
  • 115
  • 201
0

The % (read "mod" or "modulo") means divide by and return the remainder:

x = 8%3

The above expression says "divide 8 by 3 and compute the remainder. Assign this remainder to x"

inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241