Python Get Started
To get started with Python you need two things: the Python interpreter, which runs your code, and a text editor to write it in. You can follow this tutorial entirely in the browser, but setting up Python on your computer only takes a few minutes.
How to Install Python
- Windows: download the installer from python.org, run it, and tick "Add python.exe to PATH" before clicking Install
- macOS: download the macOS installer from python.org, or use Homebrew with: brew install python
- Linux: Python 3 is usually preinstalled; if not, use your package manager, for example: sudo apt install python3
Check Your Python Version
Open a terminal (Command Prompt or PowerShell on Windows) and type the command below. On macOS and Linux the command is often python3 instead of python.
python --versionPython 3.12.4
You can also check the version from inside a program using the sys module, which is handy when code must run on a specific version.
import sys
print(sys.version_info.major)
print(sys.version_info.minor)3 12
Run a Python File
Python programs are plain text files ending in .py. Create a file called hello.py in any editor (VS Code, PyCharm, or even Notepad) and add this line:
print("Hello from my first Python file")Then open a terminal in the same folder and run it by passing the file name to the interpreter:
python hello.pyHello from my first Python file
The Python Interactive Shell
If you type python with no file name, you enter the interactive shell (also called the REPL). It shows a >>> prompt and runs each line as soon as you press Enter, which is great for quick experiments. In the shell you do not even need print() to see the value of an expression. Type exit() or press Ctrl+Z then Enter (Windows) or Ctrl+D (macOS/Linux) to leave.
>>> 2 + 3
5
>>> "py" * 3
'pypypy'Choosing an Editor
Any editor works, but a code editor makes life easier with colors, auto-indentation and error hints. Visual Studio Code with the official Python extension is a popular free choice. PyCharm Community Edition is another free option built just for Python. Thonny is a very simple editor designed for absolute beginners.
Frequently asked questions
Should I type python or python3?
On Windows the command is usually python (or py). On macOS and many Linux systems, python3 is the safe choice because python may be missing or point to an old version.
Why does Windows say python is not recognized?
Python was not added to your PATH during installation. Re-run the installer, choose Modify, and enable the PATH option, or use the py launcher instead.
Which Python version should I install?
Install the latest stable Python 3 release from python.org. Everything in this tutorial works on Python 3.10 and newer.