Corrections - Tom
Compare changes
- Tom Reclik authored
```
```
```
Generators in python are special functions that remember their state each time you call them. Remeber that with the "normal" function we have seen earlier, we call the function, do our computations or other actions, maybe define local variables, etc. We may return the result of what the function does - but then the fuction is "forgotten".
In some cases, we may want to remember the state of the function. For example, we could read from a very large file: If it's very large, we cannot keep it in memory, but need to parse the content one line at the time. However, it would be very cumbersome to open a file, read one line, remember which line we have read, close the file, open the file, jump to the appropriate place, etc. \
```
```
```
There are many situations where this might be useful. For example, you might want to add additional print statements for debugging purpuses without clogging up your code, check the type of variables you pass to the function without changing the function itself, you might want to time how long the execution of a function takes, how much memory it consumes, etc.
```
```
```
```
```