In Python, whenever we use
print() the text is written to Python’s sys.stdout, whenever
input() is used, it comes from sys.stdin, and whenever exceptions occur it is written to sys.stderr. We can redirect the output of our code to a file other than stdout. But you may be wondering why one should do this? The reason can be to keep a log of your code’s output or to make your code shut-up i.e. not sending any output to the stdout. Let’s see how to do it with the below examples.
Example 1: Writing to stderr instead of stdout.
Example 2:Writing to the stdout
- Python - sys.stdout.flush()
- Python | Testing Output to stdout
- Python end parameter in print()
- Print with your own font using Python !!
- Python | sep parameter in print()
- How to print without newline in Python?
- Print first m multiples of n without using any loop in Python
- Python | Output using print() function
- Python | Print Alphabets till N
- Python program to print Emojis
- Print Colors in Python terminal
- Python | Print diagonals of 2D list
- Print objects of a class in Python
- Print lists in Python (4 Different Ways)
- Python | Print the initials of a name with last name in full
- Pretty Print JSON in Python
- Python | file parameter in print()
- Python | Print all sublists of a list
- Print all subsequences of a string in Python
- Python program to print all even numbers in a range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.