In Python 2.7 (interactive mode), both:
print("Hey Joe")
and:
print "Hey Joe"
give output:
"Hey Joe"
What is the difference? When should I use the former and when the latter?
Thank you
In Python 2.7 (interactive mode), both:
print("Hey Joe")
and:
print "Hey Joe"
give output:
"Hey Joe"
What is the difference? When should I use the former and when the latter?
Thank you
What is the difference?
Generally print 'something'
is called print statement and print("something")
is called print function. Print function has been introduced with Python 3
. Other than that looking at the basic usage you won't notice any difference. However, you could find more here.
When should I use the former and when the latter?
If you want to make your code both Python 2.7 and Python 3 compliant than you should use print function, it is safe to import it with Python 2 and Python 3 it makes difference only with Python 2.
from __future__ import print_function