Skip to content

Latest commit

 

History

History

ep077

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Today I talk about the basics of generator functions and how you'd type annotate them!

Setup commands

virtualenv venv
. venv/bin/activate
pip install mypy

Interactive examples

Python

import t
for thing in t.my_range(10):
    print(thing)

gen = t.my_range(10)
gen
next(gen)
next(gen)
next(gen)
next(gen)

gen = t.my_range(10)
while True:
    try:
        value = next(gen)
    except StopIteration:
        break
    else:
        print(value)

list(range(10))

import t
for x in t.my_range(10):
    print(f'got x: {x}')

Bash

python t.py