Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

print in Python 2

print is one of the keywords that changed between Python 2 and Python 3. In Python 2 it does not need parentheses, in Python 3 it is a function and it needs to have parentheses.

print "hello"
print "world"
print "Foo", "Bar"
hello
world
Foo Bar
print "hello",
print "world"
print "Foo", "Bar"
hello world
Foo Bar

No newline, but a space is added at the end of the output and between values.

import sys

sys.stdout.write("hello")
sys.stdout.write("world")
helloworld

write takes exactly one parameter