What is the result of % in Python?

前端 未结 19 1691
粉色の甜心
粉色の甜心 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:28

    Be aware that

    (3 +2 + 1 - 5) + (4 % 2) - (1/4) + 6
    

    even with the brackets results in 6.75 instead of 7 if calculated in Python 3.4.


    And the '/' operator is not that easy to understand, too (python2.7): try...

    - 1/4
    
    1 - 1/4
    

    This is a bit off-topic here, but should be considered when evaluating the above expression :)

提交回复
热议问题