<br><br><div><span class="gmail_quote">On 10/27/07, <b class="gmail_sendername">Dick Moores</b> <<a href="mailto:rdm@rcblue.com">rdm@rcblue.com</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
Win XP, Python 2.5.1<br><br>========================<br>#!/usr/bin/env python<br>#coding=utf-8<br><br>n = 10000000000 # 10 billion<br>print "type of 10 billion is", type(n)<br>n = 1000000000 # 1 billion<br>print "type of 1 billion is", type(n)
<br><br>raw_input("press enter to continue")<br><br>n = 10000000000<br>print type(n)<br>while True:<br> if type(n) == long:<br> n -= 1000000<br> print n, type(n)<br> else:<br> break
<br>print n<br>print type(n), 'HERE'<br>==========================<br><br>As an exercise in using type() I was thinking I could use it to begin<br>to find where (without looking it up) a long becomes an int. I show
<br>that the boundary is somewhere between 10 billion and 1 billion. But<br>the above script never ends--never gets to 'HERE'.<br><br>Here's part of the output:<br><br>6000000 <type 'long'><br>5000000 <type 'long'>
<br>4000000 <type 'long'><br>3000000 <type 'long'><br>2000000 <type 'long'><br>1000000 <type 'long'><br>0 <type 'long'><br>-1000000 <type 'long'>
<br>-2000000 <type 'long'><br>-3000000 <type 'long'><br>-4000000 <type 'long'><br>-5000000 <type 'long'><br>-6000000 <type 'long'><br><br>Note that it shows even 1 million and 0 to be longs, whereas
<br> >>> type(1000000)<br><type 'int'><br> >>> type(0)<br><type 'int'><br> >>><br><br>What's going on?<br><br>Thanks,<br><br>Dick Moores<br><br>_______________________________________________
<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>Hi Dick,
<div><br class="webkit-block-placeholder"></div><div>I would expect that a type change will happen if there is a need. Hence if type(n) is already long it does not have to get converted to int to accommodate something small.
</div><div><br class="webkit-block-placeholder"></div><div>I changed your program to increase from 1B to 10B and the results are as expected :)</div><div><br class="webkit-block-placeholder"></div><div><snip> - your old code
</div><div> </div><div><div>n = 1000000000 # 1 billion</div><div>print type(n)</div><div>while n < 10000000000 : # 10 billion</div><div> if type(n) == int:</div><div> n += 1000000</div><div> print n, type(n)
</div><div> else :</div><div> break</div><div><br class="webkit-block-placeholder"></div><snip> - your old code<br clear="all"><br>HTH<br>Aditya
</div>