[Tutor] bits taken by variable type
alan.gauld@bt.com
alan.gauld@bt.com
Tue, 18 Jun 2002 17:59:58 +0100
------_=_NextPart_001_01C216E9.93F2D030
Content-type: text/plain; charset="iso-8859-1"
> Coming from a C++ view point, how do you know if a variable in Python is
> unsigned long int or some other modified variable type?
In practice, why would you care?
> How do you know how much precision a number is stored at?
For integers it is
import sys
print sys.maxint
If you need longer than maxint use long integers which are arbitrarily
large(effectively)
For floats, I'm not sure. Just assume they are big enough and catch
exceptions
for when they aren't.
These are the kind of low level details that Python is trying to shield from
you.
Alan G.
------_=_NextPart_001_01C216E9.93F2D030
Content-type: text/html; charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002><FONT
face="Courier New" color=#0000ff>> </FONT></SPAN>Coming from a C++ view
point, how do you know if a variable in Python is <SPAN
class=580310017-18062002><FONT face="Courier New"
color=#0000ff> </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002><FONT
face="Courier New" color=#0000ff>> </FONT> </SPAN>unsigned long int or
some other modified variable type? <SPAN
class=580310017-18062002><FONT face="Courier New"
color=#0000ff> </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>In practice,
why would you care?</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002>></SPAN></FONT></FONT><FONT face=Arial><FONT
size=2><SPAN class=580310017-18062002> </SPAN>How do you
know </FONT></FONT><FONT face=Arial><FONT size=2>how much precision a
number is stored at? <SPAN class=580310017-18062002><FONT
face="Courier New" color=#0000ff> </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>For integers
it is</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>import
sys</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>print
sys.maxint</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>If you need
longer than maxint use long integers which are arbitrarily
large(effectively)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>For floats,
I'm not sure. Just assume they are big enough and catch exceptions
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>for when they
aren't.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>These are the
kind of low level details that Python is trying to shield from
you.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=580310017-18062002></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=580310017-18062002>Alan
G.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
------_=_NextPart_001_01C216E9.93F2D030--