I was wondering what does print >> dbfile, key
mean in python. What is the >>
supposed to do?
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.
The function basically prints the values in a list and if there is a nested list then it print it by a tab space.
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#.
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.
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
This redirects print
to a file (in this case, dbfile
).
the >>
is just a special syntax used for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With