[Python-ideas] Allow attribute references for decimalinteger

Chris Angelico rosuav at gmail.com
Fri Nov 1 12:52:24 CET 2013


On Fri, Nov 1, 2013 at 8:44 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> But seriously... accepting "1." for float 1.0 is, as far as I can tell,
> a common but not universal practice in programming languages. Being
> tolerant of missing zeroes before or after the decimal point matches how
> most people write, in my experience: dropping the leading zero is very
> common, trailing zero less so, unless they drop the decimal point as
> well. In a language like Python with distinct int and float types, but
> no declarations, dropping the decimal point gives you an int. Not much
> can be done about that.

And that's exactly why the clarity has value - because of the extreme
visual similarity between "1" (int) and "1." (float). However...

> Personally, I would never use "1." in source code, but I might use it in
> the interactive interpreter. I think it's an issue for a linter, not the
> compiler, so I'm happy with the status quo.

... I agree. Having the flexibility is handy, same as we have the
flexibility to write less-clear code in other ways. And as to the
exponent, I don't recall ever writing "1.e10" intentionally, but I
definitely write "1e10", and would be extremely surprised if a loose
dot broke that.

ChrisA


More information about the Python-ideas mailing list