[BangPypers] strange behavior
sidharth.kuruvila at gmail.com
Thu Jul 10 11:03:11 CEST 2008
Any number with a decimal point is treated as an object of type float and
the numbers without a decimal point of are treated as ints. You can use the
type function to find the type of an object.
Arithmetic operations over two types give the result in the more flexible
type, in this case that is a float.
You can use the int and float functions for type conversion
On Thu, Jul 10, 2008 at 10:30 AM, Pradeep Gowda <pradeep at btbytes.com> wrote:
> On Jul 10, 2008, at 12:54 AM, Gopal Ghosh wrote:
>> >>> 7/3
>> >>> 7/-3
>> >>> 3/7
>> >>> # again reapting the questions with one more decimal place
>> >>> 7.0/3
>> >>> 7.0/-3
>> >>> 3.0/7
>> >>> # why it is not showing the exact values in the previous cases
> Dividing Integer by an integer will give you Integer
> Dividing Integer by a float or a float by an integer will give a float.
> See this: http://docs.python.org/ref/binary.html
> However this behaviour will change to a less "surprising" 3/4 returning
> 0.75 as one would expect in python 3.0
> See: http://www.comp.leeds.ac.uk/nde/papers/
> BangPypers mailing list
> BangPypers at python.org
I am but a man.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the BangPypers