In Python 3.x, use int instead of long.
From What’s New In Python 3.0, Integers:
Answer from Jon-Eric on Stack Overflow
- PEP 237: Essentially,
longrenamed toint. That is, there is only one built-in integral type, namedint; but it behaves mostly like the oldlongtype.
NameError: name 'long' is not defined in python\google\protobuf\internal\reflection_test.py:639
django - Long type in Python-3, NameError: name 'long' is not defined - Stack Overflow
NameError: name 'long' is not defined When Using Python 3
name 'long' is not defined
What is Python NameError and what causes it?
What is the difference between NameError and AttributeError?
Why does my variable work in one cell but not another (Jupyter)?
The long() function is no longer supported by Python 3 (no pun intended). It only has one built-in integral type, named int; but it behaves mostly like the old long type. So you just need to use int() built-in function in python-3.x.
Also for more information here are the complete list of changes on integer type in python-3.x:
PEP 0237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type.
PEP 0238: An expression like
1/2returns a float. Use1//2to get the truncating behavior. (The latter syntax has existed for years, at least since Python 2.2.)The
sys.maxintconstant was removed, since there is no longer a limit to the value of integers. However,sys.maxsizecan be used as an integer larger than any practical list or string index. It conforms to the implementation’s “natural” integer size and is typically the same assys.maxintin previous releases on the same platform (assuming the same build options).The
repr()of a long integer doesn’t include the trailingLanymore, so code that unconditionally strips that character will chop off the last digit instead. (Usestr()instead.)Octal literals are no longer of the form
0720; use0o720instead.
Forget about long vs. int or about lL suffixes. Python 2.7 will promote int to long if necessary. And all integers are "long" in Python 3 (the type is renamed to int).
Assume that integers have infinite precision in Python.
To assign and print large integer in Python, just assign and print it:
x = 2**100
print(x) # -> 1267650600228229401496703205376
It works on both Python 2 and 3. The result is the same.