How to install Python and run your first script
Python installation, interpreter vs script mode, print function, comments, indentation, running .py files
Setting Up Python
Download Python from python.org. During installation on Windows, check Add Python to PATH. On macOS/Linux it is often pre-installed — confirm with python3 --version in your terminal.
Python runs in two modes. Interactive mode (python3) executes one line at a time. Script mode runs a .py file top-to-bottom. Use script mode for anything beyond quick experiments.
Your First Script
Create hello.py and run it with python3 hello.py.
# hello.py
print("Hello, World!") # prints to stdout
print("Python version: 3.x")
Key Rules
Python uses indentation (4 spaces) instead of curly braces to define blocks — this is enforced by the interpreter, not style. A # starts a single-line comment. Python is case-sensitive: Print is not the same as print.
The print() function accepts multiple arguments separated by commas and adds a space between them by default. Pass sep= or end= to control output formatting.
print("a", "b", "c", sep="-") # a-b-c
print("loading", end="...\n") # loading...
When Python runs a script, the interpreter reads it line by line from top to bottom. Any syntax error stops execution immediately and prints the line number and a brief message — read error messages carefully rather than guessing the fix. The REPL (Read-Eval-Print Loop) in interactive mode is excellent for quick experiments, but scripts are reproducible and easier to share. Keep your working scripts in a project folder with a clear name like main.py or run.py. Use a virtual environment per project so dependencies stay isolated.
