As given in the documentation -
raw_input([prompt])
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
It reads a single line from the input. If you want to read three lines from the input, you have to use three raw_input()
, you can read the three raw_input()
and append them to list . Example -
lst = [raw_input(), raw_input(), raw_input()]
Demo -
>>> lst = [raw_input(), raw_input(), raw_input()]
1
2
3
>>> lst
['1', '2', '3']
If you are redirecting standard input from a file or somewhere else, As mentioned in the comments by @KevinGuan , you can also use sys.stdin.read()
to read the complete input at once and then do split on that. Example -
import sys
x = sys.stdin.read()
print(x.split('\n'))
A sample text file -
Blah
Blah1
blah2
Result -
python a.py < a.txt
['Blah', 'Blah1', 'blah2']
But please note, if you are redirecting from a file, I would rather use open()
to read the file in python itself.