Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Generator with yield

We don't even need to use a temporary variable for it.

def number():
    yield 42
    yield 19
    yield 23

for n in number():
  print(n)

Output:

42
19
23