Python Get Started
Python · Getting Started
Theory
Getting started means three things: installing a Python interpreter, picking a place to write code, and knowing how to run it. You can download Python from python.org, or install a distribution such as Anaconda that bundles Python with data libraries. Check the install from a terminal with python --version (on macOS and Linux the command is often python3; on Windows the py launcher also works).
There are two ways to run code. In interactive mode (the >>> REPL or a Jupyter notebook) each line or cell runs as soon as you press Enter, which is perfect for exploring data. In script mode you save code in a .py file and run it with python3 my_script.py, and the whole file executes top to bottom. Editors like VS Code or PyCharm add autocomplete, error highlighting and a debugger on top of either style.
Why we use it
You need a working interpreter and a comfortable editor before you can learn anything else. Knowing the difference between a notebook and a script saves confusion later, for example why a variable still exists in Jupyter after you deleted the cell that created it.
When to use it
Use a Jupyter notebook for exploration, charts and step-by-step learning. Use .py scripts in an editor for code that must run repeatedly, be scheduled or be shared. If python is not recognised, try python3 or py, or fix your PATH.
How it works
- Install Python (python.org or Anaconda)
- Open a terminal and run python --version
- Does it print a version number? Yes: Python is installed and ready. No: Try python3 or py, or fix PATH.
- Exploring data step by step? Yes: Open Jupyter and run code cell by cell. No: Write a .py file in VS Code.
- Run the script with python3 my_script.py
- Read the output (or the error) in the terminal
Syntax
python --versionExample
python3 my_script.pyKey points
- Download from python.org or use Anaconda for data science
- Jupyter Notebook is popular for data analysis workflows
- On macOS/Linux the command is often python3, on Windows python or py
- In Jupyter, cells can run out of order, so restart and run all to be sure
- Use a virtual environment (python -m venv) to keep project libraries separate