print(): your first line of Python
A program is a list of instructions that Python runs from top to bottom. The first one to learn shows something on the screen.
print("Hello!")print shows whatever is inside its brackets. The quotes mark Hello! as text, so Python shows it as it is instead of trying to run it.
Two lines run in the order they are written, and each print starts a new line.
print("Ticket 1: I was charged twice for one order")
print("Ticket 2: My parcel has not arrived")Text and sums
Without quotes, Python works the value out before printing it. With quotes, it is only text that happens to contain a sum.
print(2 + 3)
print("2 + 3")Comments
A # starts a comment. Python ignores everything from there to the end of the line, so comments are notes for whoever reads the code next.
# Tickets that came in overnight
print("Waiting: 3") # this part is ignored tooYour first error
Leave out the closing quote and Python cannot tell where the text ends. It stops before running anything and says so.
print("Hello!)Read the last line of an error first. It names the kind of problem. The lines above it say where: the file, the line number, and a marker under the spot Python got stuck on.
Errors are normal. You will cause one on purpose in most lessons, because an error you have seen once is easy to recognise the next time.
- Print your own name.
- Print
10 - 4with quotes and without them. - Delete the closing bracket of a
printand read the last line of the error.
Little by little, you're building something great.