Is input() the stdin function in Python 3? Does that mean that when you open your filename.py program, the stdin is what the user types?
input()
reads from the standard input (called stdin
for short in some contexts), yes. No language that I know of has a function named stdin
in the standard library. When you run the program in the usual way, what the user types is supplied to standard input, yes. That's what "standard input" means. There is a separate program that is feeding what the user types to standard input (and doing a couple of other convenient things like interpreting the backspace key). Your script is not what creates the window that text is typed into.
sys.stdin
(i.e., the value stdin
defined in the sys
module) is an object that represents the standard input. This is provided so that you can use it in contexts where you're expected to specify "a file", to cause input to be read from the user instead of a file.
Is print() the stdout function in Python 3, or do you have to write to a file?
print()
writes (by default; you can supply a file
keyword argument to change this) to the standard output (called stdout
for short in some contexts), yes. All the above caveats apply: stdout
isn't a function in any language I've ever heard of, and a completely separate program is actually causing the output of your script to be displayed on screen in a pretty 80x24 white-text-on-black-background (or however you have it configured) box.
sys.stdout
is an object that represents the standard output, used similarly to sys.stdin
. You can use it explicitly with the print
function, but there's no point: it's the default.
For the Spotify puzzle, is says "Input is read from stdin". What should my file include of stdin and stdout?
The problem specification means "use the input()
function to receive input".