Python: Print to stderr

Python Basic: Exercise-52 with Solution

Write a Python program to print to stderr.

Sample Solution:-

Python Code:

from __future__ import print_function
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

eprint("abc", "efg", "xyz", sep="--")

Sample Output:



Flowchart: Print to stderr.

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to determine profiling of Python programs.
Next: Write a python program to access environment variables.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]