Sometimes, we want to read multiple lines of raw input with Python.
In this article, we’ll look at how to read multiple lines of raw input with Python.
How to read multiple lines of raw input with Python?
To read multiple lines of raw input with Python, we call the iter function.
For instance, we write
sentinel = ''
for line in iter(input, sentinel):
pass
to call iter with input and the sentinel value to create an iterator that reads multiple lines of raw input until the sentinenl value is entered.
Then we loop through the entered values with a for loop and get the entered value from line.
Conclusion
To read multiple lines of raw input with Python, we call the iter function.