9

I know that _s can be used as digit separator within numeric literals, between (groups of) digits, for instance 1_000 means 1000 and 0_0 means 00 or just 0. Today I accidentally typed a letter after the underscore, say 0_z. After pressing Enter, IPython showed the continuation prompt and the cursor: it expected more! But what? Example:

Python 3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.31.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 0_z
   ...:
   ...:
   ...: |

The vanilla Python prompt gives an expected syntax error instead:

Python 3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 0_z
  File "<stdin>", line 1
    0_z
     ^
SyntaxError: invalid decimal literal

Or course Ctrl+C gets me out of the problem. But exactly what (feature?) got me into it?

6
  • 3
    FYI it only happens since Python 3.12, with Python 3.11 there also is a syntax error. Commented Jan 7 at 13:26
  • There is the possibility it is a parser bug in iPython - I found no docs, (and no useful behavior) from this. Commented Jan 7 at 15:36
  • I'll ask around Commented Jan 7 at 15:55
  • My guess is there's an upcoming syntax change where this will be valid, and ipython has already implemented support for it. Commented Jan 7 at 16:12
  • 3
    @hpaulj you can, but that's not the point of the question. It is why that happens. Commented Jan 8 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.