This guide walks you from “I have never written Python before” to running your own small script. We focus on clear steps, real screenshots you can imagine, and explanations in simple English. By the end, you will know how to install Python, run it from the terminal, write a .py file, and understand what to learn next.
1. What is Python and why use it?
Python is a general‑purpose programming language. It is popular because the syntax is close to natural language and the standard library is rich. You can use Python for web development (for example with Django or Flask), automation scripts, data analysis with Pandas, and many more tasks.
If English is not your first language, Python is still a good choice. Most keywords are short and common: if, for, in, def. Error messages can be confusing at first, but we provide dedicated pages in the Errors & Exceptions section where you can copy the exact message and look up what it means.
2. Install Python (Windows, macOS, Linux)
The safest way is to install a recent Python 3 release from the official website.
- Visit python.org/downloads.
- Choose the latest Python 3.x version.
- Download the installer for your operating system.
2.1 Windows
Double‑click the installer and pay attention to the first screen. Make sure you tick:
Add Python 3.x to PATH
This step is very important. If you forget it, the command python may not be found in your terminal and you can see errors like 'python' is not recognized as an internal or external command.
2.2 macOS
On macOS you can either use the official installer or a package manager such as Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
After installation, the command is usually python3 instead of python.
2.3 Linux
Most modern Linux distributions already ship with Python 3. You can check with:
python3 --version
If the command is missing or too old, install it from your package manager (for example apt, dnf, or pacman).
3. Verify your installation
Open your terminal:
- Windows: Command Prompt or PowerShell
- macOS: Terminal app
- Linux: your preferred terminal emulator
Then run one of these commands (depending on your system):
python --version
python3 --version
You should see something like:
Python 3.12.1
If you get a “command not found” style error, go back to the installation step and check that Python is on your PATH. See also our guide on common installation issues in Troubleshooting a Python install (if you have created such a guide).
4. Use the interactive Python shell
The interactive shell (also called REPL) lets you try small pieces of code quickly:
python
>>> 2 + 3
5
>>> print("Hello")
Hello
>>> exit()
Things to notice:
- The
>>>prompt means Python is waiting for a command. - Expressions like
2 + 3show a result immediately. - To leave the shell, you can type
exit()or pressCtrl + Zthen Enter on Windows, orCtrl + Don macOS/Linux.
The shell is great for exploring small ideas, but real programs live in files.
5. Write your first script in a file
Create a new folder, for example python-basics, and inside it create a file called hello.py with this content:
name = "Python learner"
print("Hello,", name)
age = 25
print("Next year you will be", age + 1)
Now open your terminal in that folder. On Windows you can right‑click in the folder and choose “Open in Terminal” or “Open PowerShell window here”. On macOS/Linux, use cd to change to the directory:
cd path/to/python-basics
python hello.py # or: python3 hello.py
You should see:
Hello, Python learner
Next year you will be 26
If you see an error like SyntaxError: invalid syntax, check that you did not accidentally add extra characters or missing quotes. The SyntaxError guide shows the most common causes with examples.
6. Choose a beginner‑friendly editor
While you can write Python in any text editor, a code editor makes life easier:
- VS Code – free, cross‑platform, with Python extensions and debugging support.
- PyCharm Community – free edition focused on Python projects.
- Other editors – Sublime Text, Vim, etc. if you already know them.
Look for features like syntax highlighting, automatic indentation, and integration with virtual environments. Later, when you read our articles on type hints or FastAPI, a good editor will also help you navigate larger projects.
7. Common beginner mistakes
Here are some issues almost every new Python programmer hits, with links to deeper explanations:
- Mixing tabs and spaces – leads to IndentationError. Configure your editor to insert spaces only.
- Forgetting quotes – writing
print(Hello)instead ofprint("Hello")causes a NameError because Python thinksHellois a variable. - Running the wrong Python version – using
pythonwhen it points to Python 2 on old systems. Always preferpython3if available. - Saving with the wrong extension – your file must end with
.py, otherwise Python will not run it as code.
8. What to learn next
Once you can run simple scripts, the next step is to build a mental model of how Python stores and manipulates data. We recommend following this path:
- Read about data types (numbers, strings, lists, dictionaries, etc.).
- Learn how to group operations with functions.
- Practice with small tasks from the How‑To guides, such as reading CSV files or looping over lists with an index.
- When you see an error message you do not understand, search for it inside our Error index.
Taking these steps slowly, with many tiny experiments, is more effective than trying to read a whole book without writing code. Keep this page open as a reference while you explore the rest of the Python Basics section.