Addition of a "plus-minus" binary numeric operator
Hi all, I was wondering on whether there is any interest in introducing a "plus-minus" operator: Conceptually very simple; instead of: upper, lower = a + b, a - b use instead: upper, lower = a +- b In recent projects I've been working on, I've been having to do the above "plus minus" a lot, and so it would simplify/clean-up/reduce error potential cases where I'm writing the results explicitly. It isn't a big thing, but seems like a clean solution, that also takes advantage of python's inherent ability to return and assign tuples.
I doubt it, it seems way too specialised to be worth making into a language feature. If you want to, you can write a function: def limits(a, b): return a+b, a-b Paul On Tue, 14 Sept 2021 at 14:55, <yahbai@gmail.com> wrote:
Hi all,
I was wondering on whether there is any interest in introducing a "plus-minus" operator:
Conceptually very simple; instead of:
upper, lower = a + b, a - b
use instead:
upper, lower = a +- b
In recent projects I've been working on, I've been having to do the above "plus minus" a lot, and so it would simplify/clean-up/reduce error potential cases where I'm writing the results explicitly.
It isn't a big thing, but seems like a clean solution, that also takes advantage of python's inherent ability to return and assign tuples. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MCAS5B... Code of Conduct: http://python.org/psf/codeofconduct/
Add you can call this function plusminus Then use the funcoperators module to write : upper, lower = a +plusminus- b pip install funcoperators Le mar. 14 sept. 2021 à 16:02, Paul Moore <p.f.moore@gmail.com> a écrit :
I doubt it, it seems way too specialised to be worth making into a language feature.
If you want to, you can write a function:
def limits(a, b): return a+b, a-b
Paul
On Tue, 14 Sept 2021 at 14:55, <yahbai@gmail.com> wrote:
Hi all,
I was wondering on whether there is any interest in introducing a
"plus-minus" operator:
Conceptually very simple; instead of:
upper, lower = a + b, a - b
use instead:
upper, lower = a +- b
In recent projects I've been working on, I've been having to do the
above "plus minus" a lot, and so it would simplify/clean-up/reduce error potential cases where I'm writing the results explicitly.
It isn't a big thing, but seems like a clean solution, that also takes
advantage of python's inherent ability to return and assign tuples.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MCAS5B... Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XYRRZP... Code of Conduct: http://python.org/psf/codeofconduct/
May I ask what you are actually doing with upper and lower after creating them? Are you checking to see if another value is between? Something else? If they are always being used together and you're doing the same things with them all the time, it starts to smell like you might want to just write a class. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Tue, Sep 14, 2021 at 10:11 AM Ir. Robert Vanden Eynde < robertve92@gmail.com> wrote:
Add you can call this function plusminus Then use the funcoperators module to write :
upper, lower = a +plusminus- b
pip install funcoperators
Le mar. 14 sept. 2021 à 16:02, Paul Moore <p.f.moore@gmail.com> a écrit :
I doubt it, it seems way too specialised to be worth making into a language feature.
If you want to, you can write a function:
def limits(a, b): return a+b, a-b
Paul
On Tue, 14 Sept 2021 at 14:55, <yahbai@gmail.com> wrote:
Hi all,
I was wondering on whether there is any interest in introducing a
"plus-minus" operator:
Conceptually very simple; instead of:
upper, lower = a + b, a - b
use instead:
upper, lower = a +- b
In recent projects I've been working on, I've been having to do the
above "plus minus" a lot, and so it would simplify/clean-up/reduce error potential cases where I'm writing the results explicitly.
It isn't a big thing, but seems like a clean solution, that also takes
advantage of python's inherent ability to return and assign tuples.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MCAS5B... Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XYRRZP... Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/527MLD... Code of Conduct: http://python.org/psf/codeofconduct/
On Tue, Sep 14, 2021 at 11:58 PM <yahbai@gmail.com> wrote:
Hi all,
I was wondering on whether there is any interest in introducing a "plus-minus" operator:
Conceptually very simple; instead of:
upper, lower = a + b, a - b
use instead:
upper, lower = a +- b
In recent projects I've been working on, I've been having to do the above "plus minus" a lot, and so it would simplify/clean-up/reduce error potential cases where I'm writing the results explicitly.
It isn't a big thing, but seems like a clean solution, that also takes advantage of python's inherent ability to return and assign tuples.
As an operator, this wouldn't work, since it's ambiguous with adding negative b to a (ie "a + -b"). But as Paul said, this is perfect for a very simple function. ChrisA
Hi Yahbai You might wish to reconsider your proposal in light of existing behaviour
1+-1 0
Consider also your proposed
a, b = 2 +- 1 We know that {a, b} = {1, 3}. But which is which?
In your use case you might be better off introducing a custom type
lims = pm(2, 1) lims.lo, lims.hi (1, 3)
I hope this helps you with your code. best wishes Jonathan
participants (6)
-
Chris Angelico
-
Ir. Robert Vanden Eynde
-
Jonathan Fine
-
Paul Moore
-
Ricky Teachey
-
yahbai@gmail.com