No overflow in variables?
Larry Martell
larry.martell at gmail.com
Wed Jan 22 13:18:55 EST 2014
On Wed, Jan 22, 2014 at 11:09 AM, Philip Red
<filippo.biolcati at googlemail.com> wrote:
> Hi everyone. First of all sorry if my english is not good.
> I have a question about something in Python I can not explain:
> in every programming language I know (e.g. C#) if you exceed the max-value of a certain type (e.g. a long-integer) you get an overflow. Here is a simple example in C#:
>
> static void Main(string[] args)
> {
> Int64 x = Int64.MaxValue;
> Console.WriteLine(x); // output: 9223372036854775807
> x = x * 2;
> Console.WriteLine(x); // output: -2 (overflow)
> Console.ReadKey();
> }
>
> Now I do the same with Python:
>
> x = 9223372036854775807
> print(type(x)) # <class 'int'>
> x = x * 2 # 18446744073709551614
> print(x) # <class 'int'>
> print(type(x))
>
> and I get the right output without overflow and the type is always a 'int'.
> How does Python manages internally the types and their values? Where are they stored?
>
> Thank you for your help :)
This may help you understand:
http://www.python.org/dev/peps/pep-0237/
More information about the Python-list
mailing list