0 votes
1 view
in Python by (47.8k points)

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?

1 Answer

0 votes
by (107k points)
edited by

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:-

Related questions

0 votes
1 answer
asked 3 days ago in Python by ashely (44.2k points)
0 votes
1 answer
0 votes
1 answer
asked Sep 11, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
asked Sep 30, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...