yield expression programmized-formal interpretation. (interpretationof yield expression.)

C

castironpi

What if I say

oath= yield

or

other= yield

?

Does yield evaluate without parenthes? (Eth.)
 
G

Gabriel Genellina

What if I say

oath= yield

or

other= yield

?

Does yield evaluate without parenthes? (Eth.)

You can't use yield except in a generator function. From
<http://docs.python.org/ref/yieldexpr.html> and the grammar definition at
<http://docs.python.org/ref/grammar.txt> you can see that

assignment_stmt ::=
(target_list "=")+
(expression_list | yield_expression)

yield_expression ::= "yield" [expression_list]

The last expression_list is optional so a bare yield should be allowed in
the right hand side of an assignment, as if it were `yield None` (I think
such behavior is specified in the original PEP). Let's try:

py> def gen():
.... x = yield
.... y = yield "second"
.... yield x, y
....
py> g = gen()
py> print g.next()
None
py> print g.send(123)
second
py> print g.send(456)
(123, 456)
py> print g.send(789)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top