Learn / Programming / Python / Hello, Python

Python · Lesson 1 of 15

Hello, Python

Install Python, run your first script, and understand how the interpreter works.

  • Beginner
  • 8 min read
  • 3 objectives

What you will learn

  • Run Python from the terminal
  • Use print() and comments
  • Understand .py files

Python is an interpreted language. You write plain text in a .py file, and the interpreter reads it top to bottom, running each statement as it goes. There is no separate compile step, so you get feedback in seconds. That fast loop is one of the main reasons Python is a popular first language and a favorite for scripting, data work and web backends.

What is programming, really?

A program is a list of instructions written so precisely that a computer can follow them without ever guessing. Think of a recipe: "boil two cups of water, add the pasta, wait eight minutes." A human cook can cope with vague steps, but a computer cannot, so every step has to be exact. Python is a language designed so those exact steps read almost like plain English.

You do not need any prior experience. By the end of this lesson you will have installed Python, written a program, run it, and read your first error message, which is the most important beginner skill of all.

Where do I write Python?

  • A text editor plus a terminal: write a file ending in .py and run it with python3 file.py. This is what the rest of the course assumes.
  • VS Code (free): a friendly editor with a built-in terminal and a Run button. A great first choice.
  • The REPL: type python3 in a terminal and you get a prompt where every line runs instantly. Perfect for experiments.
  • Right here: every editor on this site with a Run button executes real Python in your browser, so you can try things without installing anything first.

Check your installation

Open a terminal and ask Python for its version. On macOS and Linux the command is usually python3; on Windows it is often python or py. Any version 3.9 or newer works for this course.

python3 --version
Output
Python 3.12.4

Your first program

print() is a built-in function. You call it by writing its name followed by parentheses, and put whatever you want displayed inside them. Text is written between quotes and is called a string. Numbers need no quotes, and Python will do the math before printing.

print("Hello, stackcone!")
print(2 + 2)
print("2 + 2 =", 2 + 2)
Output
Hello, stackcone!
4
2 + 2 = 4

Save this as hello.py and run it from the folder where you saved it:

python3 hello.py

Comments and the interpreter

Anything after a # on a line is a comment. Python ignores it, so use comments to explain why code does something, not what it does. You can also type python3 on its own to open the interactive prompt (the REPL), which is a great place to try one-liners.

# This line is ignored by Python
print("visible")  # comments can follow code too

How a program actually runs

When you run python3 hello.py, Python reads the file from the first line to the last, one statement at a time, and does what each says. It never skips ahead unless you tell it to (you will learn how in the control-flow lesson). Output from print() appears in the order the lines run.

print("step 1")
print("step 2")
print("step 3")
Output
step 1
step 2
step 3

Order matters. If you swap two lines, the output swaps too. Whenever a program surprises you, the first question to ask is: which line is running right now, and what has already happened?

Printing several things at once

print() accepts many values separated by commas and puts a space between them. Use sep= to change that separator and end= to change what comes after (the default is a new line).

print("Python", "is", "fun")
print("a", "b", "c", sep="-")
print("loading", end="...")
print("done")
Output
Python is fun
a-b-c
loading...done

Your first error, on purpose

Errors are not failure; they are the computer telling you exactly what it did not understand. Type the line below and you will see one. Read the last line first.

print("Hello)
Output
  File "hello.py", line 1
    print("Hello)
          ^
SyntaxError: unterminated string literal (detected at line 1)

Python points at the exact spot (the ^) and names the problem: the string that started with a quote never closed. Add the missing " and the error disappears.

Common mistakes

  • Missing quotes: print(Hello) fails with NameError because Python thinks Hello is a variable. Write print("Hello").
  • Mismatched parentheses or quotes: every opening ( or " needs a closing partner, or you get a SyntaxError.
  • Wrong capitalization: Python is case sensitive. Print is not print.
  • Running from the wrong folder: No such file or directory means your terminal is not in the folder that contains the file. Use cd to move there.

Key takeaways

  • A program is precise, ordered instructions; Python runs them from top to bottom.
  • print() shows values; commas add spaces, sep= and end= change the layout.
  • Run a file with python3 file.py, or experiment instantly in the REPL.
  • Read errors from the last line upward; the message tells you what went wrong.
# Write your solution here
Up next · Lesson 2Variables and TypesNames, assignment, and the core built-in types: int, float, str, and bool.