Reputation: 14141
Breaking long string literals into multiple lines is not problem, e. g.
long_string = ("This is a very very long string literal for writing it as one-line "
"literal. More appropriate is using more lines so that the code"
"will be more readable.")
But what about long integer literals, e. g.
long_number = 12312323456782556897455666645555554787825401568014564565678978201245667185
Is there some similar possibility?
Upvotes: 3
Views: 228
Reputation: 34155
You can do:
long_numer = int("1231232345678255689745"
"5666645555554787825401"
"5680145645656789782012"
"45667185")
As long as this is not in your hot codepath, the extra step should not cause issues.
Upvotes: 8
Reputation: 99630
In python, there is no max value for an integer. If you really want to do something like this, you can try
x = '12312323456782556897455666645555554787825401568014564565678978201245667185' \
+ '12312323456782556897455666645555554787825401568014564565678978201245667185'
Now, to fetch the value, you can simply do
long_number = int(x)
Except for Pep8, you are not really achieving much by doing this though.
Another way you can parse the value could be using ast
import ast
long_number = ast.literal_eval(x)
Upvotes: 4