And methods like isnumeric, isdigit, and isdecimal unfortunately take a bit of studying to figure out, so I recommend either avoiding them or using them carefully.
Let's discuss:
โข The main reason generators are used
โข The 2 ways to make a generator
โข Lesser known generator features
โข Why and when to use generators
Thread ๐งต๐
Generators are typically used as lazy iterables.
By "lazy" I mean that they don't actually compute their values until they absolutely need to.
Essentially generators will "generate" their next value as soon as they're asked for it.
Here's a generator of every .py file in my home directory:
>>> from pathlib import Path
>>> py_files = Path.home().rglob("*.py")
>>> py_files
<generator object Path.rglob at 0x7f5a6721c900>
(the rglob method on pathlib.Path objects always returns a generator)