Skip to content
skillbld
Day 1 of 14 25 minInterpreterprint()Comments

What Python is, how your code actually runs, and writing your very first program.

By the end of today you can

  • Explain what Python is and where it is used
  • Describe how the Python interpreter runs your code
  • Write and run a program with print()
  • Use comments to explain your code

Welcome to day one. Today is about getting comfortable: what Python is, what happens when you press Run, and writing a program that talks back.

What is Python?

Python is a general-purpose programming language designed to be easy to read. Its code looks a lot like plain English, which is why it is one of the most popular first languages, and also why professionals use it for serious work.

Mind map · click a dot to fold, drag to pan

How your code runs

When you run a Python file, a program called the interpreter reads your code, translates it into simpler instructions (bytecode), and executes them one line at a time, top to bottom.

Diagram

That last dotted arrow matters: if a line has a mistake, Python stops and shows a traceback telling you where and why.

Your first program

The classic first program prints a greeting. Edit it, then press Run: this is real Python running in your browser.

main.py · editable
Output
Press Run to execute this code.

print() is a function: a named action. The text inside the quotes is a string. Python prints each print() on its own line.

Printing more than one thing

multiple.py
print("Day", 1, "of", 14)
print("2 + 3 =", 2 + 3)

When you pass several values separated by commas, print() puts a space between them. Notice that 2 + 3 is calculated before it is printed.

Comments

A comment is a note for humans. Python ignores everything after a # on a line.

main.py · editable
Output
Press Run to execute this code.

When things go wrong

Errors are normal, and reading them is a skill. Run this and look at the message:

main.py · editable
Output
Press Run to execute this code.
Part of the messageWhat it tells you
line 2Where Python got confused
SyntaxErrorThe kind of problem
The text after itA hint about how to fix it

Recap

  • Python is a readable, interpreted, general-purpose language.
  • The interpreter runs your code top to bottom, one line at a time.
  • print() shows output; # starts a comment.
  • Errors stop the program and print a traceback. Read it from the bottom up.

Knowledge check

Test what you learned

4 questions · pick an answer to see if you're right

0/4
  1. 1

    What kind of language is Python?

  2. 2

    What does print("Hi") do?

  3. 3

    Which line is a comment in Python?

  4. 4

    What happens when Python reaches a line with an error?

Finished today's lesson?