Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'static': 0.04; 'output': 0.05; 'args)': 0.09; 'constructor': 0.09; 'objects,': 0.09; 'overflow': 0.09; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'bound,': 0.16; 'immutable,': 0.16; 'int64': 0.16; 'integers.': 0.16; 'internally': 0.16; 'overflow.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'values?': 0.16; 'java,': 0.16; 'language': 0.16; 'example': 0.22; 'programming': 0.22; 'string,': 0.24; 'question': 0.24; 'certain': 0.27; 'header:X-Complaints-To:1': 0.27; 'generally': 0.29; 'needed.': 0.30; 'int,': 0.31; 'object.': 0.31; 'void': 0.31; '(e.g.': 0.33; 'something': 0.35; 'good.': 0.35; 'everyone.': 0.36; 'subject:?': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'space': 0.40; 'how': 0.40; 'simple': 0.61; 'first': 0.61; 'size.': 0.65; 'skip:1 20': 0.65; 'here': 0.66; 'between': 0.67; 'believe': 0.68; 'exceed': 0.68; 'limit': 0.70; 'upper': 0.74; 'power': 0.76; 'grow': 0.77; 'subject::': 0.85; 'philip': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:No overflow in variables? Date: Wed, 22 Jan 2014 13:26:36 -0500 (EST) Organization: news.gmane.org References: X-Gmane-NNTP-Posting-Host: dpc6744192108.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390415074 news.xs4all.nl 2863 [2001:888:2000:d::a6]:42336 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64521 Philip Red Wrote in message: > 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)) # > x = x * 2 # 18446744073709551614 > print(x) # > 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 :) > In python, every value is an object. Some, like lists, can grow over time, and there's no specific upper limit in size. Others, like int, or string, are immutable, so the constructor can calculate just how much space is needed. In java, and I believe in C#, they make a distinction between unboxed and boxed integers. The former are NOT objects, and have a specific upper bound, generally based on some power of 2. -- DaveA