In this lesson, you’ll learn about the advanced generators methods of .send()
, .throw()
, and .close()
. To practice with these new methods, you’re going to build a program that can make use of each of the three methods.
As you follow along in the lesson, you’ll learn that yield
is an expression, rather than a statement. You can use it as a statement, but you can manipulate a yielded value. You are allowed to .send()
a new value back to the generator. You’ll also handle exceptions with .throw()
and stop the generator after a given amount of digits with .close()
.
zell0ss on June 17, 2020
Great tutorial,
A curiosity I seem unable to answer, why the palindromes found are:
11 111 1111 10101
instead
11 101 1001 10001
At first I thought that was because we send 10 ** (digits) and it got incremented just afterwards so it will skip 101, 1001, … I changed it to 10 ** (digits) -1 but got the same result.
I know it is not strictly generator related, but nonetheless, Im curious!