Python · Lesson 0.1

How Python runs here

Run your first lines of Python, print results, and leave notes in your code.

Every code box on this site is real Python running in your browser. Change the code, press Run (or Ctrl + Enter), and see what it prints.

1Print something

print() shows a value below the code box. Text goes inside quotes; numbers and sums don't need them.

print("Hello, data!")
print(2 + 3)
Python

Practice

Print the text Ready to learn Python.

# Write your code below
Python

2Code runs from top to bottom

Python runs one line at a time, starting at the top. So the order of your lines is the order of the output.

print("Step 1: load the data")
print("Step 2: clean it")
print("Step 3: report")
Python

Practice

These lines are in the wrong order. Rearrange them so the output reads load, then clean, then report.

print("report")
print("load")
print("clean")
Python

3Comments are notes for humans

Anything after a # is a comment, and Python skips it. Use comments to explain why the code does something.

# Monthly visitors to the shop (made-up numbers)
print(1200)  # January
# print(9999)  this line is switched off, so it never prints
Python

Practice

The second line is a note, not code, so the program stops with an error. Turn it into a comment so the code runs and prints 42.

answer = 42
This is the answer to the question
print(answer)
Python

4Print several things at once

Give print() several values separated by commas, and it puts a space between them.

print("Rows:", 120)
print("Total sales:", 300 + 450, "dollars")
Python

Practice

Use one print() with two values to show Orders: 75, where 75 is a number, not text.

# Write your code below
Python

Tip

You can always press Reset on an example to get the original code back, and Show answer under a practice if you're stuck.