Run your first Python program, experiment in the REPL, and keep each project isolated with a virtual environment so packages never clash.
Why: Python is a program that runs the code in a text file. You save your code in a file ending in .py and run it by typing "python" followed by the file name in your terminal. (On some systems the command is "python3".)
Create a file called hello.py with one line:
print('Hello, Python!')Then run it from the same folder:
python hello.pyWhy: REPL stands for Read-Eval-Print Loop — a live prompt where you type Python and instantly see the result. It is perfect for quick experiments. Start it by typing "python" with no file name. Type exit() or press Ctrl+Z then Enter (Windows) / Ctrl+D (Mac, Linux) to leave.
python>>> 2 + 2>>> name = 'Ada'>>> name.upper()>>> exit()Why: a virtual environment is a private copy of Python for one project. Each project keeps its own packages in its own folder, so upgrading a package for project A can never break project B. venv is built into Python — nothing to install.
Create one (the second "venv" is just the folder name people use by convention):
python -m venv venvWhen: activate the environment in every new terminal before you work. Your prompt changes to show (venv) so you know it is on. "deactivate.bat" turns it back off.
Windows (PowerShell):
venv\Scripts\Activate.ps1Mac / Linux:
source venv/bin/activate
Comments
Why: a comment is a note for humans that Python ignores when it runs. Anything after a # on a line is a comment. Use them to explain why the code does something.