Question about typing: ints/floats

Shashwat Anand anand.shashwat at gmail.com
Thu Mar 4 02:06:54 CET 2010


yes
you can also try:
>>> float(a)/b
0.33333333333333331


On Thu, Mar 4, 2010 at 5:15 AM, Wells <thewellsoliver at gmail.com> wrote:

> This seems sort of odd to me:
>
> >>> a = 1
> >>> a += 1.202
> >>> a
> 2.202
>
> Indicates that 'a' was an int that was implicitly casted to a float.
> But:
>
> >>> a = 1
> >>> b = 3
> >>> a / b
> 0
>
> This does not implicitly do the casting, it treats 'a' and 'b' as
> integers, and the result as well. Changing 'b' to 3.0 will yield a
> float as a result (0.33333333333333331)
>
> Is there some way to explain the consistency here? Does python
> implicitly change the casting when you add variables of a different
> numeric type?
>
> Anyway, just  curiosity more than anything else. Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100304/92289656/attachment.html>


More information about the Python-list mailing list