Python for AIPython 3.10+ · Pydantic 2.12
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
33 small wins to finish your pathNext lesson

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.

Example
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.

Example
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.

Example
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.

Example
# Tickets that came in overnight
print("Waiting: 3")  # this part is ignored too

Your first error

Leave out the closing quote and Python cannot tell where the text ends. It stops before running anything and says so.

Example
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.

Try it yourself
  • Print your own name.
  • Print 10 - 4 with quotes and without them.
  • Delete the closing bracket of a print and read the last line of the error.

Little by little, you're building something great.