6

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.

Vishal Anand
  • 474
  • 1
  • 4
  • 17

1 Answers1

6
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
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
  • 3
    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` – Maciej Gol Jan 11 '14 at 07:51
  • @kroolik Thanks :) Removed that from the answer. – thefourtheye Jan 11 '14 at 07:53
  • 1
    @kroolik, (in Python 2.x). – falsetru Jan 11 '14 at 07:53
  • @falsetru, yes. Also, link to the [docs](http://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex) (2nd paragraph) – Maciej Gol Jan 11 '14 at 07:57