Entering a very large number
bartc <bc at freeuk.com> writes:
> On 25/03/2018 15:53, Joe Pfeiffer wrote:
>> ast <none at gmail.com> writes:
>>> C = int(
>> After following the thread for a while... you will, of course, simply
>> have to do a string to int conversion no matter what approach you take
>> to writing it.
> What, even with you write this:
> C = 12
I'm having a hard time parsing that sentence. If you're pointing out
that when someone writes an int of reasonable length they don't mess
with strings and explicit int conversions, of course you're right. This
question is specficially about "very large" numbers.
>> The number is a string of digits; it has to be converted
>> to the internal representation.
> Which is usually done by a compiler, and it will only do it once not
> each time the line is encountered in a running program. (Although a
> compiler will also do the conversion when the line is never executed!)
If you're using compiled python, yes (though I don't really know how the
bytecode represents long numbers like this, or whether it would optimize
away the explicit int conversion). Since it's a constant string, it
would be a *really* easy optimization.
>> Even if you write
>> C =
>> the conversion happens.
> But not at runtime.
If it's not in a loop, only once at runtime in any case. Does the
interpreter save away constants as it goes, so it would only have to be
done once in any case?