←back to thread

317 points est | 1 comments | | HN request time: 0.202s | source
Show context
oooooof ◴[] No.17448560[source]
What is it? The link points to a discussion more deep than I’m willing to read.
replies(10): >>17448567 #>>17448570 #>>17448571 #>>17448572 #>>17448575 #>>17448579 #>>17448584 #>>17448591 #>>17448617 #>>17448638 #
hultner ◴[] No.17448584[source]
You're allowed to do assignments inside of expressions

E.g.

    if(x:=f() is not None):
        print(x)
You can read more about it here: https://www.python.org/dev/peps/pep-0572/
replies(1): >>17448672 #
majewsky ◴[] No.17448672[source]
I'm immediately skeptical after seeing this example because I'm not sure if the first line parses as:

  if (x := f()) is not None:
or as:

  if x := (f() is not None):
replies(2): >>17448788 #>>17449070 #
1. sametmax ◴[] No.17449070[source]
That's why parenthesis are mandatory.