What Does % Sign Mean in Python [Duplicate]

What Does % Sign Mean in Python [Duplicate]

what does % sign mean in python? I looked it up and it said that it's a format for the print part, but it's not on the part of the printing so it didn't really help.. here's the code anyway:

a = 5
b = 6
c = 7
for i in range((a+b)*4):
  if i%c == 0:
    print(i)
1

2 Answers

The % is the modulo it will return the rest of an euclidian division

Ex :

10 % 3 == 1 #True because 10//3 = 9 and the rest is 1
10 % 10 == 0 #True because 10//10 = 1 and the rest is 0

It denotes a Modulus operator; gives the remainder of the left value divided by the right value. like:

5%3=2

15%30=15
David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.