I’ve come across lines like this in Python:
print "Let's talk about %s." % my_name
However, I’ve seen cases in Ruby where these two have equivalent output:
print "Let's talk about #{my_name}."
print "Let's talk about %s." % my_name"
Is there only one way to print the same line in Python?
In Python there are also several ways:
all generate the same output. However, use of the .format method (available since Python v 2.6) is encouraged over the old-style
%(To quote from the What’s New in 3.0: “…the % operator is still supported; it will be deprecated in Python 3.1 and removed from the language at some later time.“)Lastly, as of Python v3.x
printis a function, so all print statements require().