Skip to main content
Engineering LibreTexts

2.8: Long Integers

  • Page ID
    17030
  • If you compute fibonacci(50), you get:

    >>> fibonacci(50)
    12586269025L
    

    The L at the end indicates that the result is a long integer, or type long. In Python 3, long is gone; all integers, even really big ones, are type int.

    Values with type int have a limited range; long integers can be arbitrarily big, but as they get bigger they consume more space and time.

    The mathematical operators work on long integers, and the functions in the math module, too, so in general any code that works with int will also work with long.

    Any time the result of a computation is too big to be represented with an integer, Python converts the result as a long integer:

    >>> 1000 * 1000
    1000000
    >>> 100000 * 100000
    10000000000L
    

    In the first case the result has type int; in the second case it is long.

    Exercise \(\PageIndex{1}\)

    Exponentiation of large integers is the basis of common algorithms for public-key encryption. Read the Wikipedia page on the RSA algorithm (http://en.Wikipedia.org/wiki/RSA_(algorithm)) and write functions to encode and decode messages.