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

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Mar 5 13:56:46 CET 2014


On 5 March 2014 12:42, Chris Angelico <rosuav at gmail.com> wrote:
> 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

>From a syntactic perspective Python doesn't have syntax for general
complex literals. There is only syntax for creating imaginary literals
and it is trivial to create a complex number by adding a real and an
imaginary one.

3F could create a Fraction with the integer value 3 so that a/b gives
a rational number:

>>> from fractions import Fraction as F
>>> a = 2
>>> b = F(3)
>>> a/b
Fraction(2, 3)

I don't understand why you say that can't be done.


Oscar


More information about the Python-ideas mailing list