Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
If you are working in the interactive interpreter, you may be running into a conflict with the "magic" variable `_` which the interactive interpreter creates to hold the result of the last evaluated statement. So when you evaluate `x`, and that returns the string "robert", it also gets assigned to `_`. But you can't easily delete `_` because it lives in the builtin namespace, not the global namespace. This happens with anything, not just match statements: >>> x = "spam eggs" >>> x 'spam eggs' >>> _ 'spam eggs' >>> del _ # Not a global, can't delete it! Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_' is not defined So I think the weird behaviour with _ that you have stumbled over is a red herring. However, it does seem to me that *perhaps* the assignment to x shouldn't be occurring at all. So that may be a bug in the match statement? ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45323> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com