LPTHW - Exercise 9: Printing, Printing, Printing

LPTHW - Exercise 9

Simple copy and print here but a few things we haven't seen before - namely those \n things in the months variable string.

When running the script the output on the months variable are displayed on separate lines, so those \n things obviously indicate a newline/carriage return be inserted.

I guess this is a way to get new lines on a string enclosed by single or double quotes, i.e. a way of doing it without using triple quotes and manually setting up the format youself.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "\nJan\nFeb\nMar\nApr\nMay\nHun\nJul\nAug"

print("Here are the days: ", days)
print("Here are the months: ", months)

print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""")

Learn Python the Hard Way Study Drills

1. Check your work, write down your mistakes, try not to make them on the next exercise.

OK!

Source files

As ever, source files on GitLab.

Spotted something wrong with this content? Tell me!

Get in touch on Twitter, GitLab or by email.