Behavior of Python ** and % operators with big numbers

前端 未结 4 1265
一整个雨季
一整个雨季 2021-01-23 11:03

When I put in Python interpreter a ** b % c with large a (20 figures) b (4 figures) c (20 figures) I saw that Python calculates it pretty fast, almost like pow (a,b,c). I expect

4条回答
  •  执笔经年
    2021-01-23 11:50

    If you are typing into the Python interpreter something like:

    20937505974095709374 ** 3438
    

    Then seeing a couple of seconds wait. Then trying:

    20937505974095709374 ** 3438 % 6
    

    And seeing no wait, and wondering why there is a difference, then the delay that you see in the first instance is actually the time your terminal takes to buffer and print the huge number you just created to the screen.

提交回复
热议问题