Python long integer input

13,696
n = int(raw_input())

This will convert the input to an integer. Since Python employs arbitrary precision arithmetic, we don't have to worry about how big the number is.

>>> n = int(raw_input())
100000000000000
>>> n
100000000000000L
Share:
13,696
Vishal Anand
Author by

Vishal Anand

Updated on June 12, 2022

Comments

  • Vishal Anand
    Vishal Anand almost 2 years

    How can one take a "long int" input in Python 2.7?

    P.S. I tried various variations of n=(*(raw_input())) but to no avail.

  • Maciej Gol
    Maciej Gol over 10 years
    There is long type in Python, but it's different from long of C standard and similar - it has arbitrary precision, and any int object beyond int precision becomes long. >>> type(int(10000000000)) == long; True
  • thefourtheye
    thefourtheye over 10 years
    @kroolik Thanks :) Removed that from the answer.
  • falsetru
    falsetru over 10 years
    @kroolik, (in Python 2.x).
  • Maciej Gol
    Maciej Gol over 10 years
    @falsetru, yes. Also, link to the docs (2nd paragraph)