Time to run real code
In lesson 1-1 you learned that a program is a list of exact instructions. Now you will run one.
Python is a programming language designed to be readable. You write Python as plain text, and a program called the Python interpreter reads your text from top to bottom and carries out each instruction, one line at a time. Carrying out the instructions is called running (or executing) the program.
The code editor below is live. When you press Run, your code is sent to an isolated sandbox environment, executed, and whatever the program prints comes back as output. You do not need to install anything.
The first instruction every programmer learns is print. Despite the name, it has nothing to do with paper. print means: show this on the screen.
Code exercise · python
Press Run and watch the output panel. This one line is a complete program.
Anatomy of that line
print("Hello, world!")
Three pieces:
printis the name of a built-in instruction. Python ships with many of these ready to use.- The parentheses
()hold the input you give to the instruction. In Python, an instruction's inputs always go inside parentheses right after its name — that is how the interpreter tells "the thing to do" apart from "the thing to do it with". "Hello, world!"is that input: a piece of text. Text in code is called a string, and the quotes mark where the string starts and ends. The quotes themselves are not printed.
Every symbol matters. Delete a quote or a parenthesis and Python refuses to run, reporting a syntax error, which means "I could not understand this as valid Python". Getting error messages is completely normal. Professionals see them all day. Read the message, fix the line, run again.
Quiz
In print("Hello, world!"), what do the quote marks do?
Code exercise · python
Your turn. Write one line of Python that prints exactly: I am learning to code. (including the final period). Press Run to check yourself.