Why Python don't accept 03 as a number?

Henrik Bengtsson henrik.bengtsson at gmail.com
Sat Dec 8 01:53:45 EST 2018


A comment from the sideline: one could imagine extending the Python syntax
with a (optional) 0d prefix that allows for explicit specification of
decimal values. They would "complete" the family:

* 0b: binary number
* 0o: octal number
* 0d: decimal number
* 0x: hexadecimal number

I understand that changing the syntax/parser is a major move. I wouldn't be
surprised if others brought up 0d before.

My $.02

Henrik


On Fri, Dec 7, 2018, 21:12 Cameron Simpson <cs at cskk.id.au wrote:

> On 07Dec2018 20:24, Jach Fong <jfong at ms4.hinet.net> wrote:
> >Ian at 2018/12/8 UTC+8 AM11:28:34 wrote:
> >> What is it exactly that you're trying to accomplish with this? Perhaps
> >> there's a better way than using eval.
> >
> >This problem comes from solving a word puzzle,
> >    ab + aa + cd == ce
> >Each character will be translate to a digit and evaluate the correctness,
> >    03 + 00 + 15 == 18
>
> Then you should be evaluating the digits and assembling values from
> them. Not trying to shoehorn a string through something that _might_
> accept this string and do what you want. In Python 2 it will accept your
> string and not do what you want; at least in Python 3 it doesn't accept
> your string.
>
> My point here is that the structure of your puzzle doesn't map directly
> into a naive python statement, and you shouldn't be pretending it might.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list