擅长:python、mysql、java
<p>可以将生成器函数与<code>enumerate</code>结合使用:</p>
<pre><code>string = "this is a test"
def marquee(some_string):
for idx, char in enumerate(some_string):
yield some_string[0:idx] + char.upper() + some_string[idx + 1:]
for s in marquee(string):
print(s)
</code></pre>
<p>这就产生了</p>
<pre><code>This is a test
tHis is a test
thIs is a test
thiS is a test
this is a test
this Is a test
this iS a test
this is a test
this is A test
this is a test
this is a Test
this is a tEst
this is a teSt
this is a tesT
</code></pre>