3 ms·
> I'm not sure if the way that you're using yield within the if and while statements works correctly. You're right... Perhaps I'm not so surprised that `if y
by OJFord 7y ago
> I'm not sure if the way that you're using yield within the if and while statements works correctly.
You're right...
Perhaps I'm not so surprised that `if yield == val:` is a SyntaxError, but that `yield` can't be used as an rvalue to a walrus operator (that the `while` example essentially boils down to) surprises me:
>>> char = yield
File "<stdin>", line 1
SyntaxError: 'yield' outside function
>>>
>>> # i.e. OK, that's the error we want if it works
>>>
>>> got_b = (char := yield) == 'b'
File "<stdin>", line 1
got_b = (char := yield) == 'b'
^
SyntaxError: invalid syntax