def foo(x):
if x == y:
blah
elif x == z:
blah1
if x == y:
blah2
elif x == a:
blah3
if x == y:
blah
elif x == y:
blah4
if x == b:
blah5
elif x == c:
blah6
def foo(x):
if x == 6:
print 'six'
elif x == 3:
print 'three'
yield
if x > 4:
print 'greater than four'
else:
print 'not greater than four'
yield
能产生
>>> f = foo(6)
>>> f
<generator object foo at 0x1004b25a0>
>>> next(f)
six
>>> next(f)
greater than four
>>> next(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
就像伍布尔说的,你可以用发电机来做这个,至少如果我知道你想要什么的话。我在野外见过几次,但很少见到。你知道吗
能产生
不过,也许有更好的方法来做你想做的事。你知道吗
相关问题 更多 >
编程相关推荐