runtime
01 / 250
lesson 01 Python Setup & First Programs · beginner

Run your first program

Python reads your program from the top and does each line in turn. print() shows the result.

You'll be able to
  • Run a program and read what it printed in the console
  • Predict the order of the output from the order of the lines
  • Print text, numbers and empty lines
The idea

The examples in this course come from Runtime Market, a small online shop. An order number such as O104839 is one order from that shop.

A Python program is a list of instructions in a file, here main.py. When you press Run, Python reads the file from the first line to the last and carries out each instruction in turn. print() is the instruction that shows something in the console.

Run each example to see what it prints. Running examples doesn't count toward progress.

example-1.py · Three instructions, three lines
print("Order O104839")
print(142.77)
print("Status: delivered")

Text goes inside quotes, either "…" or '…'. The quotation marks tell Python that the characters are text. They are not printed. print("7") and print(7) both show 7 in the console. Numbers don't need quotes. print() with nothing inside prints an empty line.

example-2.py · Numbers, text and an empty line
print("Items in cart:")
print(3)
print()
print('Total due:')
print(142.77)

Order matters. Python never skips ahead or goes back. If you swap two lines, their output swaps too.

Mistakes to avoid: a missing closing quote or bracket stops the whole program before anything prints; lesson 5 shows how to read Python's message about it. And print is written in small letters: Print is a different name.

Review
  • Python runs main.py from the first line to the last.
  • print() shows text (in quotes) or numbers. The quotes are not printed. print() with nothing inside prints an empty line.
  • Change the order of lines and you change the order of the output.

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

Run your first program — Python Setup & First Programs · Runtime