Getting Started with Python
Python · Reference cheat sheet
Getting Started with Python
Python · Reference cheat sheet
📋 Overview
Python is a readable, general-purpose language used for scripting, web backends, data work, and automation. You write .py files (or use the interactive REPL) and run them with the python (or python3) interpreter.
🔧 Core concepts
| Idea | Meaning |
|---|---|
| Interpreter | Runs your code line by line |
| REPL | Interactive prompt (>>>) for trying snippets |
| Script | A .py file you run from the terminal |
| Module | A reusable .py file you can import |
| Package | A folder of modules (often with __init__.py) |
Install check: open a terminal and run python --version (or python3 --version). Use a virtual environment (venv) so project packages stay isolated.
Typical first workflow:
- Install Python 3 from python.org (or your OS package manager).
- Create a folder for practice files.
- Write
hello.py, then runpython hello.py.
💡 Examples
Check the version:
python --version
# Python 3.12.xStart the REPL:
python>>> 2 + 2
4
>>> print("hi")
hi
>>> exit()Create and run a script:
# hello.py
print("Hello from a file!")python hello.pyCreate a virtual environment (recommended):
python -m venv .venv
# Windows PowerShell:
.\.venv\Scripts\Activate.ps1
# macOS/Linux:
source .venv/bin/activate
pip install requests⚠️ Pitfalls
- On some systems
pythonis missing and you must usepython3. - Mixing system Python and project packages without
venvcauses version conflicts. - Indentation is syntax in Python — tabs vs spaces can break files.
- Saving as
.txtor wrong encoding can confuse beginners; use UTF-8.pyfiles.