total and utter newbie

trewornan treworn at cyberspace.org
Tue Nov 12 19:55:15 EST 2002


John Hunter wrote:
>>>>>>"rockbox" == rockbox  <rockboxb at webmail.co.za> writes:
>>>>>
> 
>     rockbox> Hi.  I hope that this is the right group to post this
>     rockbox> problem in. If not then I appologise.
> 
> Ahh yes, the oldest newbie problem in the book :-)
> 
> In current versions of python (as in C and many other programming
> languages) an integer divided by an integer returns an integer, so
> 
> x = 3/2      #x is 1
> 
> but if either number is a floating point number, then the division you
> are expecting is used
> 
> x = 3.0/2.0  # x = 1.5
> 
> The trick is to add a decimal point and a 0 to your number unless you
> want integer behavior
> 
> x = 3.0/2  # this is also 1.5
> 
> This is being phased out of python, and is slated for destruction.
> 
> Recent versions of python (2.2?) allow you to use
> 
> from __future__ import division
> 
> at the beginning of your program to get the division you are
> expecting.
> 
> See http://www.python.org/peps/pep-0238.html for the official
> information about these changes, and how how to do old fashioned
> integer division under the new system when you want to.
> 
> Have fun!
> John Hunter
> 

Is there anything like a cast in Python? Just out of interest.

M




More information about the Python-list mailing list