Modifying the value of a float-like object

Dave Angel davea at
Wed Apr 15 11:59:39 CEST 2009

Steven D'Aprano wrote:
> On Tue, 14 Apr 2009 14:45:47 -0400, Dave Angel wrote:
>> The answer to your original question is no.  If the value can be
>> changed, then it doesn't behave like a float.  And that's not just a
>> pedantic answer, it's a serious consideration.
> Oh nonsense. Many programming languages have mutable floats.
That's irrelevant.  Python doesn't.  So introducing one will quite 
likely alter the OP's code's behavior.  It doesn't matter if it's 
possible, it matters whether the existing code's behavior might change, 
and of course if a future maintainer might have trouble making sense of it.

BTW, just what languages have mutable floats?  I don't think I've come 
across any since Fortran (on a CDC 6400), and I don't think that was 
deliberate.  In that implementation it was possible to change the value 
of a literal 2.0 to something else.  I remember writing a trivial 
program that printed the value of 2.0 + 2.0 as 5.0.  It was about 1971, 
I believe.  I know I haven't used Fortran since 1973.

If you're going to use the fact that many languages pass arguments by 
reference, then you should realize that a reference to a float is a 
different kind of variable than a float.  And although that language 
might use the terminology of mutable, it wouldn't mean the same thing 
that mutable does in Python.

More information about the Python-list mailing list