Lesson 2 of 6

Getting Started

There are two ways to talk to Python, and they serve two very different purposes. The REPL (Read-Eval-Print Loop) is a conversation — you type one line, Python answers immediately, and you keep going back and forth. A script is a letter — you write the whole thing first, save it to a file, then hand the entire thing to Python to run top to bottom. You'll use both constantly: the REPL for quick experiments, scripts for anything you want to keep.

Open a terminal and type python3 (or just python on some systems). You'll land in the REPL, marked by a >>> prompt waiting for input:

>>> print("hello")
hello
>>> 2 + 2
4

💡 The Bottom Line

The REPL is for quick, throwaway experiments — type a line, see the result instantly. A script is a .py file you write once and run whenever you need it. Learn to move between both: experiment in the REPL, then graduate the working idea into a script.

Your first script

Save this in a file called hello.py:

print("Hello, Python")
name = "there"
print("Nice to meet you,", name)

Then run it from the terminal, in the same folder as the file:

python3 hello.py

You should see both lines printed. That's the whole loop you'll repeat for every program you ever write: write the file, run it, read the output, adjust, run it again.

🙋 There Are No Dumb Questions

Q: Why does print need parentheses?
A: In Python, print is a function — a reusable piece of behavior you invoke by name. The parentheses are where you hand it the values you want it to act on, called arguments. You'll meet functions properly in Lesson 5, but you'll be calling them from day one, so it's worth getting used to the shape now: name(argument).

The rule that makes Python look different: indentation

Most languages use curly braces { } to mark "this code belongs together." Python uses something bolder: whitespace itself is the syntax. Lines indented under a statement are understood to belong to it — no braces required:

if 5 > 3:
    print("five is bigger")
    print("this line belongs to the if, too")
print("this line does not — it always runs")

This isn't just a style preference Python enforces — it's the actual mechanism the language uses to know where a block starts and ends. Two blocks at different indentation levels are, as far as Python is concerned, structurally different code.

⚠️ Watch Out

Never mix tabs and spaces for indentation in the same file — Python will refuse to run and raise an IndentationError, and the mismatch can be invisible in some editors. Pick one (the community standard is 4 spaces) and configure your editor to use it consistently. Most code editors do this automatically once you tell them the file is Python.

It feels strict at first if you're coming from a language with braces, but it has a real payoff: every Python codebase you'll ever read is formatted the same way, because the formatting is the code. There's no argument to have about where the brace goes — there's only one way to write it that actually runs.

🔧 Try It Yourself

Open the REPL (or a script) and try breaking the indentation rule on purpose, just to see the error:

if 1 < 2:
print("oops")

You should get an IndentationError: expected an indented block. Now fix it by indenting the print line with four spaces and run it again. Seeing the error once, deliberately, makes it far less confusing the first time you hit it by accident.

✅ Quick Check

What does Python use to determine which lines belong to a block of code, like the body of an if statement?


Next up: now that you can run code, it's time to give it something to work with. Lesson 3 covers variables and Python's core data types — and the surprisingly flexible way Python handles typing.

← Back to
Next →