Correct, I left out a bit, not wisely. I am trying to remember the last time (outside of classes) I have ever had to use bitwise operators nontrivially and it may have been around 1980 when I had to implement an encryption algorithm. Of course, when I was working in UNIX, I often had to combine bitwise things to specify all kinds on 1-bit flags when say opening a file.
So we now have so many candidates FOR COMPLETENESS to add as variants of the Walrus operator, that I might vote to do NONE of them, if anyone ever asked. I do want to remind people though that these operators often serve a purpose in Python as using them means you do not need to specify an argument twice and you can specify some dunder methods that make it more efficient to type: obj += obj2 rather than obj = obj + obj2 So there may be a valid argument, not just about completeness, to implement something BUT as we got along fine before a walrus came along, ... or did we? -----Original Message----- From: Python-list <python-list-bounces+avigross=verizon....@python.org> On Behalf Of MRAB Sent: Wednesday, October 27, 2021 9:21 PM To: python-list@python.org Subject: Re: walrus with a twist :+= or ... On 2021-10-28 02:06, Avi Gross via Python-list wrote: > I just realized I left out **= so my apologies. Are there other such > abbreviations and does anyone use them? > You forgot about the bitwise operators: |= &= ^= > -----Original Message----- > From: Python-list > <python-list-bounces+avigross=verizon....@python.org> On Behalf Of Avi > Gross via Python-list > Sent: Wednesday, October 27, 2021 8:57 PM > To: python-list@python.org > Subject: walrus with a twist :+= or ... > > I realized that the person seeking completeness in Python may next ask > why the Walrus operator, :=, is not properly extended to include a > whole assortment of allowed assignment operators > > > I mean in normal python programs you are allowed to abbreviate > > x = x + 5 > > with > > x += 5 > > Similarly you have other operators like > > x *= 2 > > And, of course, the constantly used operator: > > x %= 2 > > So how does one extend a walrus operator if they ever decide to give > in and add it to the language just for completeness? > > Sadly, a simple test shows they neglected to use a :+= operator in the > latest: > >>>> (walrus := 2) > > 2 > >>>> walrus > > 2 > >>>> (wallrus :+= 2) > > File "<stdin>", line 1 > > (wallrus :+= 2) > > ^ > > SyntaxError: invalid syntax > > (Yes, I know how to spell walrus, but making a point.) > > On a serious note, if it was ever considered a good idea, what would > be an acceptable sequence of symbols that might not break or confuse > existing programs and what would we call it? I mean what animal, of course. > > What do these look like in some fonts? :+= :-= :*= :/= :%= > > Or do we not just add a colon in front and make it a tad different as in :=+ > or :+=: or maybe realize the futility of perfection! After all, you can > easily use some functions to get a result such as: > > x := func(x, "+", 5) > > x := func_add(x, 5) > > or many other work-arounds. > > Can we all forget I asked? I am sort of being sarcastic. > -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list