Re: Question about typing: ints/floats

2010-03-13 Thread Albert van der Horst
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 >>

Re: Question about typing: ints/floats

2010-03-03 Thread Steven D'Aprano
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

Re: Question about typing: ints/floats

2010-03-03 Thread Steven D'Aprano
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

Re: Question about typing: ints/floats

2010-03-03 Thread MRAB
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

Re: Question about typing: ints/floats

2010-03-03 Thread Benjamin Kaplan
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

Re: Question about typing: ints/floats

2010-03-03 Thread Shashwat Anand
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

Re: Question about typing: ints/floats

2010-03-03 Thread Chris Rebert
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

Re: Question about typing: ints/floats

2010-03-03 Thread Mensanator
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

Re: Question about typing: ints/floats

2010-03-03 Thread Zeeshan Quireshi
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

Question about typing: ints/floats

2010-03-03 Thread Wells
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 wi