Run your first program
Python reads your program from the top and does each line in turn. print() shows the result.
- 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 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.
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.
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.
- Python runs
main.pyfrom 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.