Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of >> in print statement

I was wondering what does print >> dbfile, key mean in python. What is the >> supposed to do?

like image 468
David Avatar asked Dec 25 '10 23:12

David


People also ask

What is print >> in Python?

Python print() Function The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.

What does end =' t mean?

The function basically prints the values in a list and if there is a nested list then it print it by a tab space.

What does print statement mean?

The PRINT statement sends data to the display terminal or to another specified print unit. PRINT[ON unit#] print-expr. Parameter(s) ON unit# Specifies that data should be output to a Spooler print unit unit#.

What does end do in the print () statement?

The end key of print function will set the string that needs to be appended when printing is done. By default the end key is set by newline character. So after finishing printing all the variables, a newline character is appended. Hence, we get the output of each print statement in different line.


2 Answers

It should be noted that the >> syntax is specific to Python 2.x. In Python 3.x, that syntax goes away and code needs to be changed as follows:

print >>f, "Hello world"           # Python 2.x

print("Hello world", file=f)       # Python 3.x
like image 135
Greg Hewgill Avatar answered Oct 20 '22 13:10

Greg Hewgill


This redirects print to a file (in this case, dbfile).

the >> is just a special syntax used for this.

like image 43
James Avatar answered Oct 20 '22 13:10

James