program1.py:
a = "this is a test"
for x in a:
print(x)
program2.py:
a = """this is a test
with more than one line
three, to be exact"""
for x in a:
print(x)
program3.py:
import sys
for x in sys.stdin:
print(x)
infile.txt:
This is a test
with multiple lines
just the same as the second example
but with more words
Why do program1 and program2 both output each character in the string on a separate line, but if we run cat infile.txt | python3 program3.py
, it outputs the text line by line?