roytang.net Posts Photos Archives About

Subscribe: RSS JSON

2019 November

  • I've been using Python for well over 10 years, and I still don't have an intuitive mastery of one of its keywords: yield. Everytime I see it in someone's code I need to stop and mentally remind myself what it does. I figured I'd write a devnote to help improve my recall. Typically, yield is used in a function with a loop, like so: def some_func(lim): for i in range(0, lim): yield i yield means the function returns a "generator" that can be used as an iterable in a loop: for val in some_func(5): print(val) You can also straight up

    read more (172 words)

2019 August