How can I combine two print statements that both use string formatting?


#1

Question

How can I combine two print statements that both use string formatting?

Answer

The best way to demonstrate is with an example, check out the code below:

print “This is my first %s.” % (“string”)
print “But I will be combined %s“ % (“one day soon!”)

print “This is my first %s. But I will be combined %s” % (“string”, “one day soon!”)

We started off with two separate strings being formatted and simply combined the strings and variables being inserted. The lesson wants the same thing!


FAQ: Learn Python - Date and Time - Grand Finale