This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Arithmetics behaving strange and magic underscore
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, lastmohican
Priority: normal Keywords:

Created on 2007-01-31 18:36 by lastmohican, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31155 - (view) Author: Sascha Peilicke (lastmohican) Date: 2007-01-31 18:36
Hello, i just found some strange things going around, could you please tell me if this is desired:

>>> 3 + 4
7
>>> 3 +- 4
-1
>>> 3 +-+ 4
-1
>>> 3 +-+- 4
7
>>> 3 +-+-+ 4
7
>>> 3 +-+-+- 4
-1
>>> 3 +-+-+-+ 4
-1
>>> 3 +-+-+-+- 4
7

This was found in Python 2.4.4c1. And also another one:


>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name '_' is not defined
>>> 3 == 3
True
>>> _
True
>>> 3 
3
>>> _
3


So what the hell is '_' something very strange indeed.
msg31156 - (view) Author: Sascha Peilicke (lastmohican) Date: 2007-01-31 18:39
I also found these working on the following:

Python 2.5 (r25:51908, Oct  6 2006, 15:22:41) 
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu4)] on linux2

Seems to be a common 'problem' ?
msg31157 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-01-31 20:22
In your first example, all + and - except the first + are seen as unary operators and modify the 4.

In your second example: "_" is a convenience variable in the interactive interpreter and always bound to the
latest expression result. At startup, there is no such result.
msg31158 - (view) Author: Sascha Peilicke (lastmohican) Date: 2007-01-31 22:07
Ok, claryfies something, but i don't think, that this should be valid syntax. Maybe it is not a real bug, but definitly a gotcha.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44533
2007-01-31 18:36:12lastmohicancreate