In article ,
MRAB wrote:
>Zeeshan Quireshi wrote:
>> On Mar 3, 6:45 pm, Wells 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
>>
On Wed, 03 Mar 2010 17:06:01 -0800, Chris Rebert wrote:
> But yes, internally, Python converted the int to a float before doing
> the addition.
[pedantic]
To be precise, Python created a *new* float from the int, leaving the
original int alone. Because ints and floats are objects, if Python
ac
On Wed, 03 Mar 2010 15:45:51 -0800, Wells wrote:
> 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.1)
This is design fla
Zeeshan Quireshi wrote:
On Mar 3, 6:45 pm, Wells 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 th
On Wed, Mar 3, 2010 at 6:45 PM, Wells 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 tre
yes
you can also try:
>>> float(a)/b
0.1
On Thu, Mar 4, 2010 at 5:15 AM, Wells 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
On Wed, Mar 3, 2010 at 3:45 PM, Wells 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.
Remember Python is dynamically typed. Values have types, but variables
don't (I could do a = "foo" at t
On Mar 3, 5:45 pm, Wells 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' an
On Mar 3, 6:45 pm, Wells 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' an