'Does the print() Function Count as a Standard Output and does input() Count as a Standard Input?

Last week, I signed up for a reverse-engineering coding competition. The rules stated "All input and output to the program must be through the standard streams (stdin and stdout, respectively")." Upon reading that, I looked up their official practice test and started writing my code. I encountered many roadblocks because I was unfamiliar with the sys.stdin.read and sys.stdout.write functions. Then last night while I was researching ways to make my code better, I stumbled upon a coding blog stating the input() function is in fact a form of stdin. I looked around even more on the internet and came across a separate blog from another company that said relatively the same thing. So... is this true? Is input() and print() a form of stdin and stdout I can use for my competition?



Solution 1:[1]

Yes, actually the print function uses sys.stdout as its write() method.

In the python documentation, you can find that the print function is defined by:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

which file argument must be an object with a write(string) method. If it is not present or None, sys.stdout will be used. So by default print uses sys.stdout.

Also for the input function, you can find this sentence in the documentation:

stdin is used for all interactive input (including calls to input()).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak