What does the % in a calculation? I can't seem to work out what it does.

Does it work out a per cent of the calculation for example:- 4 % 2 is apparently equal to 0. How?

Login

0 votes

There are many uses of %, it is used in string formatting operations like %= to substitute values into a string also it is used to evaluate remainder and mod:

**Below is the example regarding that:-**

x = 'abc_%(key)s_'

x %= {'key':'value'}

print(x)

'abc_value_'

In your case, 4%2 is 0 because when you divide 4 by 2 it will give remainder as 0.

To know more about this you can have a look at the following video tutorial:-