Generator returning same value
<p>So I have this code:</p>

<pre><code>def odds():
    number = 1

    while True:
        yield number
        number += 2

nums = odds()

for _ in range(100):
    print(next(nums))
</code></pre>

<p>and this one:</p>

<pre><code>def odds():
    number = 1

    while True:
        yield number
        number += 2

for _ in range(100):
    print(next(odds()))
</code></pre>

<p>The first part, when run, returns <code>1, 3, 5 ...</code>, but the second one: <code>1, 1, 1, 1...</code>, just 1's. Why is that?
Note that the difference is that , in the second part, I didn't type <code>nums = odds()</code>.</p>