6 ms·
> You can require additional brackets around assignment if you use the returning value (or otherwise it's syntax error). They did that with the new one anyway.
by thomasahle 8y ago
> You can require additional brackets around assignment if you use the returning value (or otherwise it's syntax error). They did that with the new one anyway.
They only did it if the := is at the root level. The following is completely legal:
if match := re.search(pat, text):
`print("Found:", match.group(0))
or
[y := f(x), y**2, y**3]
- bluecalm 8y agoGreat, I haven't used := thing yet. I think it's more elegant like that.