3 ms·
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.
by hultner 8y ago
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/ https://www.python.org/dev/peps/pep-0572/
- majewsky 8y agoI'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):
- icebraining 8y ago:= overrules everything except a comma, so it's the latter. Still, I agree it's potentially confusing.
- sametmax 8y agoThat's why parenthesis are mandatory.