LPTHW Exercise 8: Printing, Printing

Learn Python the Hard Way by Zed Shaw .: More printing using the newer format():

formatter = "{} {} {} {}"

print(formatter).format(1, 2, 3, 4)
print(formatter).format("one", "two", "three", "four")
print(formatter).format(True, False, False, True)
print(formatter).format(formatter, formatter, formatter, formatter)
print(formatter).format(
    "I had this thing.",
    "That you could type up right.",
    "But it didn't sing.",
    "So I said goodnight."
)

Output:

$ python e08.1.py
1 2 3 4
one two three four
True False False True
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
I had this thing. That you could type up right. But it didn't sing. So I said goodnight.
$

More • pythonprogramming