Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64519
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-01-22 10:09 -0800 |
| Message-ID | <dd6a72bf-b1c4-4868-9cfe-76dfac8b8787@googlegroups.com> (permalink) |
| Subject | No overflow in variables? |
| From | Philip Red <filippo.biolcati@googlemail.com> |
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 :)
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
No overflow in variables? Philip Red <filippo.biolcati@googlemail.com> - 2014-01-22 10:09 -0800
Re: No overflow in variables? Larry Martell <larry.martell@gmail.com> - 2014-01-22 11:18 -0700
Re:No overflow in variables? Dave Angel <davea@davea.name> - 2014-01-22 13:26 -0500
Re: No overflow in variables? Philip Red <filippo.biolcati@googlemail.com> - 2014-01-22 10:32 -0800
Re: No overflow in variables? Chris Angelico <rosuav@gmail.com> - 2014-01-23 05:26 +1100
Re: No overflow in variables? Roy Smith <roy@panix.com> - 2014-01-22 15:55 -0500
Re: No overflow in variables? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-23 11:22 +1300
Re: No overflow in variables? Philip Red <filippo.biolcati@googlemail.com> - 2014-01-22 10:48 -0800
Re: No overflow in variables? random832@fastmail.us - 2014-01-22 18:13 -0500
Re: No overflow in variables? Christian Heimes <christian@python.org> - 2014-01-23 10:14 +0100
Re: No overflow in variables? Chris Angelico <rosuav@gmail.com> - 2014-01-23 20:36 +1100
csiph-web