←back to thread

317 points est | 1 comments | | HN request time: 0.201s | 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 #
est ◴[] No.17448572[source]
It's a controversial PEP https://www.python.org/dev/peps/pep-0572/ which allows you to write Python like this:

    def foo():
        if n := randint(0, 3):
            return n ** 2
        return 1337


    [(x, y, x/y) for x in input_data if (y := f(x)) > 0]
replies(7): >>17448580 #>>17448633 #>>17448694 #>>17448731 #>>17448946 #>>17449000 #>>17449023 #
sluukkonen ◴[] No.17448731[source]
Would've making regular assignment an expression broken too much existing code?
replies(2): >>17448916 #>>17449059 #
1. icebraining ◴[] No.17448916[source]
Probably not, since expressions can already be statements. But that would allow dangerous code like "if a = 3", which I don't think the Python devs would want to allow.