[Python] Python pow() and modulus

Discussão em 'Python' iniciado por Stack, Novembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    The pow() function in Python3 provide the values for exponents.

    >>>pow(2, 3)
    8


    Python3 has support to negative exponents that is [​IMG] can be represented using pow(10, -1). When I calculated pow(4, -1, 5), it gave the output 4.

    >>> pow(4, -1, 5)
    4


    I couldn't understand how the value 4 was calculated because, in the background, it performs [​IMG] and it didn't return a value 4 as a reminder when I calculated manually.

    When -ve value is passed in two values it responds with the desired output as a manual method.

    >>> pow(4, -1)
    .25


    What is the difference when calculating a negative exponent with a modulus?

    Continue reading...

Compartilhe esta Página