Python Get Started
You can start writing Python right now in the playgrounds on this site. Sooner or later, though, you will want Python on your own computer so you can run scripts, work with files and install packages. This lesson shows both.
Is Python already installed?
Many Linux and macOS systems ship with Python 3. Open a terminal (Command Prompt or PowerShell on Windows) and ask for the version:
python3 --versionPython 3.12.4
On Windows the command is usually python or py instead of python3. Your version number may differ — anything from 3.10 upwards works for this course.
Installing Python
| System | Recommended way |
|---|---|
| Windows | Download the installer from python.org and tick "Add python.exe to PATH" |
| macOS | Installer from python.org, or brew install python |
| Linux | Your package manager, e.g. sudo apt install python3 |
Tip: On Windows, the Microsoft Store version of Python also works well for learning.
Writing your first script
A Python program is just a text file whose name ends in .py. Create a file called hello.py in any text editor (VS Code, PyCharm, or even Notepad) with this content:
print("Hello from a file!")Then run it from the terminal, in the folder where you saved it:
python3 hello.pyHello from a file!
The interactive shell (REPL)
If you run python3 with no file name you get the interactive shell, also called the REPL (Read–Eval–Print Loop). You type one statement, press Enter, and see the result immediately. It is perfect for quick experiments.
$ python3
>>> 2 + 3
5
>>> "py" * 3
'pypypy'
>>> exit()The >>> is the prompt. In the shell you don't even need print() — the value of an expression is shown automatically. In a script file, you do need print() to see anything.
Running code in this course
Every example marked with a ▶ Run button is a complete Python program. Try this one — it prints the version of Python that is running it:
import sys
major = sys.version_info.major
print("Running Python", major)
print("Is it Python 3?", major == 3)Running Python 3
Is it Python 3? True
The first line, import sys, loads a module from the standard library. Modules have their own lesson later on.
Python as a calculator
Python evaluates arithmetic just like a calculator, following the normal order of operations:
print(7 + 5)
print(10 - 4 * 2)
print((10 - 4) * 2)
print(7 / 2)12
2
12
3.5
Choosing an editor
| Editor | Why people like it |
|---|---|
| VS Code + Python extension | Free, fast, great debugger and linting |
| PyCharm Community | Full Python IDE with smart refactoring |
| IDLE | Comes with Python, very simple |
| Jupyter Notebook | Mix code, output and notes — popular for data work |
Note: Whatever editor you choose, configure it to indent with 4 spaces. That is the standard style for Python code.
Test yourself
What file extension do Python scripts use?
- .pt
- .py
- .pyt
- .python
What does the >>> symbol indicate?
- A comment
- A shell redirect
- The interactive Python prompt
- A syntax error