Skip to content

Underscore variable (_) not restored as last expression result after deletion when first input is a string #15000

Description

@Darshan808

Description

Steps to reproduce

  • Run the following in a fresh IPython session:
In [1]: 'test'
Out[1]: 'test'

In [2]: _ = 42

In [3]: _
Out[3]: 42

In [4]: del _

In [5]: 6+6
Out[5]: 12

In [6]: _
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 _

NameError: name '_' is not defined

Expected behavior

IPython should display _ as the special variable containing the last result (here, 12), consistent with CPython REPL.

Environment

  • IPython version: 9.5.0
  • Python version: 3.13.5
  • OS: Linux Ubuntu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions