What does "print >>" do in python?

PythonServer Side ProgrammingProgramming

"print >>" is a syntax to extend the standard 'print' statement so that it can be used to print to any file-like object, instead of the default sys.stdout. So it can be used to print directly to files.


For example, you open a file called my_file, then you can write to it using:

 >>> my_file =open("my_file")
>>> print >>my_file, "Hello World"

This will write "HelloWorld" to my_file. It can also be used with other file like objects.

Updated on 12-Dec-2019 07:02:49