What is the result of % in Python?

前端 未结 19 1704
粉色の甜心
粉色の甜心 2020-11-22 00:57

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

Does it work out a percent of the calculation for example: 4 % 2

19条回答
  •  粉色の甜心
    2020-11-22 01:14

    I have found that the easiest way to grasp the modulus operator (%) is through long division. It is the remainder and can be useful in determining a number to be even or odd:

    4%2 = 0
    
      2
    2|4
     -4
      0
    
    
    11%3 = 2
    
      3
    3|11
     -9
      2
    

提交回复
热议问题