[Python-ideas] Python Numbers as Human Concept Decimal System

Chris Angelico rosuav at gmail.com
Wed Mar 5 13:42:14 CET 2014


On Wed, Mar 5, 2014 at 11:30 PM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> I just though that 3F looks sufficiently distinct from the
> way it's typically done in C.

3F would be about -16C wouldn't it?

(Not painting any bike sheds when it's that cold, thanks!)

I'm not sure I like the idea of tagging the end of the expression.
Currently, the nearest Python has to that is the complex notation:

>>> 1+2j
(1+2j)

And that works just fine when considered to be addition:

>>> a=1
>>> b=2j
>>> a+b
(1+2j)

So really, what Python has is a notation for a j-suffixed float,
meaning a complex number with no real part. You can't do that with
Fraction:

>>> a=2
>>> b=3F
>>> a/b

What I'd prefer would be some modification of the division operator.
We currently have two ways to divide an integer by an integer:

>>> 1234/10
123.4
>>> 1234//10
123

Adding a third operator, defined only between two integers, would be
cleaner than tagging one of the integer literals. Exactly what that
operator would be is hard to say, but I'm sure there's a combination
that would look right and not be ambiguous.

>>> 1234-/-10
Fraction(617, 5)

I can't think of anything good, though.

ChrisA


More information about the Python-ideas mailing list