Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Walrus Operator in 3.8
#11
Algol and Algol68 both used the walrus operator for assignment to avoid the ambiguity between assignment and equality testing. Personally I find Python's use of == for equality testing ugly and would prefer a special operator like := (APL uses a left arrow) for all assignments, leaving = for equality testing only. That's not going to happen.

But I don't see why := is needed at all. Take the construct

m = myfunc(args)
if m == 27:
    do something
using walrus notation it becomes

if m := myfunc(args) == 27:
    do something
but why can't Python interpret the following in the same way?

if m = myfunc(args) == 27:
    do something
or to make the intent clearer (but parentheses really not required)

if (m = myfunc(args)) == 27:
    do something
if "myfunc(args)" results in a value which is then assigned to m, then certainly m is an expression that evaluates to the same value, and "m = myfunc(args)" should be allowed in the conditional the same as "myfunc(args)".
Reply


Messages In This Thread
Walrus Operator in 3.8 - by nilamo - Feb-07-2019, 10:53 PM
RE: Walrus Operator in 3.8 - by micseydel - Feb-08-2019, 12:16 AM
RE: Walrus Operator in 3.8 - by wavic - Feb-15-2019, 08:17 PM
RE: Walrus Operator in 3.8 - by metulburr - Feb-15-2019, 08:42 PM
RE: Walrus Operator in 3.8 - by Larz60+ - Feb-15-2019, 08:48 PM
RE: Walrus Operator in 3.8 - by ichabod801 - Feb-15-2019, 08:53 PM
RE: Walrus Operator in 3.8 - by micseydel - Feb-15-2019, 11:45 PM
RE: Walrus Operator in 3.8 - by nilamo - Feb-16-2019, 04:29 PM
RE: Walrus Operator in 3.8 - by ichabod801 - Feb-16-2019, 04:58 PM
RE: Walrus Operator in 3.8 - by Larz60+ - Feb-16-2019, 05:16 PM
RE: Walrus Operator in 3.8 - by Reverend_Jim - Jul-19-2019, 01:04 PM
RE: Walrus Operator in 3.8 - by ichabod801 - Jul-19-2019, 01:24 PM
RE: Walrus Operator in 3.8 - by DeaD_EyE - Jul-19-2019, 03:41 PM
RE: Walrus Operator in 3.8 - by nilamo - Jul-19-2019, 04:25 PM
RE: Walrus Operator in 3.8 - by metulburr - Jul-19-2019, 04:34 PM
RE: Walrus Operator in 3.8 - by Reverend_Jim - Jul-20-2019, 04:15 PM
RE: Walrus Operator in 3.8 - by metulburr - Jul-20-2019, 04:29 PM
RE: Walrus Operator in 3.8 - by snippsat - Jul-20-2019, 07:52 PM
RE: Walrus Operator in 3.8 - by metulburr - Sep-20-2019, 12:17 AM
RE: Walrus Operator in 3.8 - by wavic - Sep-20-2019, 05:50 AM
RE: Walrus Operator in 3.8 - by DeaD_EyE - Sep-20-2019, 06:06 AM
RE: Walrus Operator in 3.8 - by metulburr - Sep-20-2019, 12:12 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020