Welcome to Day 1. Before we talk about what Python is, run some.
The box below is a real Python editor. Press Run — the first run takes a few seconds while Python itself downloads into your browser, and every run after that is instant.
print("Hello, Python")That is a complete Python program. One line, no boilerplate, no compiler.
There is no main(), no semicolon, no class wrapped around it — a Python file
is simply a list of instructions, run top to bottom.
What just happened
print is a function: a named piece of behaviour you can call. You call a
function by writing its name followed by parentheses, and you put the values it
should work on inside those parentheses. Those values are called arguments.
print("Hello, Python")
# ↑ ↑
# name argument
print takes whatever you give it and writes it to the output. Give it several
arguments and it prints them all, separated by spaces.
print("Hello,", "Python", "-", 7, "days")
print("one")
print("two")Notice two things. Text is wrapped in quotes; the number 7 is not. And each
print starts a new line — that is why one and two do not run together.
Strings and numbers are different things
"Hello" is a string — a piece of text. 7 is an integer. The quotes are
what make the difference, and Python takes them seriously:
print("7" + "7")
print(7 + 7)Adding two strings glues them together; adding two numbers adds them. Same symbol, different behaviour, decided entirely by what you gave it. We will come back to this on the next page — it is the source of most first-week confusion.
Break it on purpose
Delete a quote mark in the box above and press Run. Python will refuse the program and point at the line. Reading error messages early is a real skill, and you cannot break anything here — the code runs in your browser tab and nowhere else.
Comments
A line starting with # is ignored by Python. Comments are notes for humans —
for other people reading your code, and for you in three months when you have
forgotten why you wrote something.
# Work out the tip on a restaurant bill.
bill = 40
# 18% is the usual rate here.
print(bill * 0.18) # a comment can also sit after codeGood comments explain why, not what. # add 1 to x next to x = x + 1
tells the reader nothing they could not see. # skip the header row tells them
something real.
Whitespace has meaning
In most languages, indentation is decoration. In Python it is syntax — it is how Python knows which lines belong to what. You will use this properly on Day 2, but you can meet the error now:
print("first line")
print("this line is indented for no reason")IndentationError: unexpected indent. Python is telling you that an indented
line has to be inside something, and there is nothing here for it to be
inside. Remove the leading spaces and it runs.
Print a small profile
Using only print, produce exactly this output:
Name: Ada
Role: Programmer
Years active: 8Try it in the box before opening the solution.
# Your code hereShow one solution
print("Name: Ada")
print("Role: Programmer")
print("Years active: 8")One print per line of output is the obvious approach, and obvious is good.
There is a shorter way using \n inside a single string, and a much better way
using variables — which is exactly where the next lesson starts.
What you learned
- A Python program is a list of statements, run from top to bottom.
print(...)writes values to the output; several arguments are separated by spaces.- Text goes in quotes and is called a string; numbers do not.
#starts a comment, which Python ignores.- Indentation is part of the language, not decoration.
Next up: giving your values names, so you can use them more than once.