Getting started with Python means installing Python 3, checking the terminal command, creating a .py file, and running that file from a project folder.
Keep terminal commands in the terminal and Python code inside .py files. This one separation prevents many first-day setup mistakes.
A clean beginner setup uses a code editor, a small project folder, python -m pip for packages, and a virtual environment when a project needs third-party libraries.
Getting started with Python means setting up Python on your computer, choosing a code editor, learning how to run Python programs, and understanding the basic project workflow. Once this setup is clear, the rest of Python learning becomes much easier.
In this lesson, you will learn how to install Python, check that it works, run code in different ways, create your first script, set up a simple project folder, and use tools like pip and virtual environments.
Download Python from the official website: python.org/downloads. Use the latest stable Python 3 release unless your project specifically requires another version.
After installing Python, check the installed version from the terminal. This confirms that Python is available from the command line.
python --version
# Example output:
# Python 3.12.4
# On some macOS/Linux systems:
python3 --version
# Check pip version:
pip --version
python -m pip --version
You can write Python code in any text editor, but a good editor makes learning faster by providing syntax highlighting, autocomplete, error hints, formatting, and terminal integration.
| Editor | Best For | Notes |
|---|---|---|
| VS Code | Most beginners and professionals | Free, fast, excellent Python extension, built-in terminal |
| PyCharm | Professional Python projects | Full IDE with strong refactoring, debugging, and project tools |
| IDLE | Absolute beginners | Comes with Python, simple but limited |
| Thonny | First-time programmers | Simple interface and visual debugging support |
| Jupyter Notebook | Data science and experiments | Great for step-by-step exploration and charts |
Interactive mode, also called the REPL, lets you type Python code and immediately see the result. It is useful for quick experiments, testing expressions, and learning syntax.
Use the REPL for small checks. For real programs, create a .py file so your code can be saved, edited, and reused.
python
>>> print("Hello, Python!")
Hello, Python!
>>> 10 + 5
15
>>> name = "Asha"
>>> print("Welcome", name)
Welcome Asha
>>> exit()
A Python source file normally ends with the .py extension. For example, main.py, app.py, or hello.py.
# main.py
print("Hello, World!")
name = input("Enter your name: ")
print(f"Hello, {name}! Welcome to Python.")
a = 10
b = 3
print(f"{a} + {b} = {a + b}")
print(f"{a} - {b} = {a - b}")
print(f"{a} * {b} = {a * b}")
print(f"{a} / {b} = {a / b:.2f}")
python main.py
# Or:
python3 main.py
Python uses indentation to define blocks of code. A block is a group of statements that belongs together, such as the body of an if statement, loop, function, or class.
score = 85
if score >= 50:
print("Passed")
print("Good job!")
else:
print("Failed")
print("Try again")
def greet(name):
message = f"Hello, {name}"
return message
As your code grows, keep files organized inside a project folder. Even a beginner project should have a clear structure.
| File or Folder | Purpose |
|---|---|
| main.py | Main entry point of the program |
| helpers.py | Reusable helper functions |
| requirements.txt | List of third-party packages used by the project |
| README.md | Project notes, setup steps, and usage instructions |
| tests/ | Test files for checking program behavior |
my_python_project/
|-- main.py
|-- helpers.py
|-- requirements.txt
|-- README.md
`-- tests/
`-- test_main.py
pip is Python's package installer. It lets you install third-party libraries from PyPI, the Python Package Index.
# Install a package
python -m pip install requests
# Show installed packages
python -m pip list
# Save project dependencies
python -m pip freeze > requirements.txt
# Install dependencies from a file
python -m pip install -r requirements.txt
A virtual environment is an isolated Python workspace for one project. It prevents packages from different projects from interfering with each other.
# Create virtual environment
python -m venv .venv
# Activate on Windows PowerShell
.venv\Scripts\Activate.ps1
# Activate on Windows Command Prompt
.venv\Scripts\activate.bat
# Activate on macOS/Linux
source .venv/bin/activate
# Deactivate when done
deactivate
| Symptom | Likely Cause | Fix |
|---|---|---|
| python is not recognized | Python is not added to PATH | Reinstall Python and select Add Python to PATH, or use the full Python path |
| pip installs to wrong Python | Multiple Python versions installed | Use python -m pip install package |
| Permission error while installing packages | Installing globally without permission | Use a virtual environment |
| IndentationError | Missing or inconsistent indentation | Use 4 spaces consistently |
| Script opens then closes quickly | Double-clicking a script on Windows | Run it from terminal with python file.py |
Before moving to variables and data types, prove that your setup can run a saved file. Open the project folder in your editor, create main.py, run it from the terminal, and confirm the output appears where you expect.
If a command fails, check the exact command, the current folder, and the Python executable. Setup bugs usually come from PATH, a closed terminal session, or running the command from the wrong directory.
When packages enter the project, create a virtual environment first. Then use python -m pip so the package installs into the same Python installation that runs your code.
0 of 2 checked
Try this next
0 of 3 completed
The terminals may have different PATH values or activated environments. Check where python or Get-Command python to see which executable each one finds.
It runs pip through the selected Python interpreter, avoiding accidental installs into another Python version.
No. Create a virtual environment so each project can keep its own package versions.
Explore 500+ free tutorials across 20+ languages and frameworks.