Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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 Sep 11, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
asked Nov 24, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...