PY-01-001-P · Primer — What Python Is & Running Code
The idea in one sentence
Python is a high-level, general-purpose programming language whose code you don't hand to the machine directly — instead you hand it to a running program called the interpreter (the reference one is CPython), and that program can read your code two ways: one line at a time in a live conversation called the REPL, or all at once from a saved .py script.
Why it exists
Computers only truly understand raw binary machine instructions, which are miserable for humans to write and read. Every programming language exists to close that gap — to let you write something legible like print("Hello") and have it eventually turn into instructions a CPU can run. Languages differ mostly in how that translation happens and when.
Python's designers chose to make the translation happen live, by a program that's always there while your code runs. That single choice buys you the thing beginners love most: you can type one line, see the result immediately, fix it, and try again — no lengthy "build" step standing between you and the answer. Python exists to make that loop as short and friendly as possible, so that experimenting, learning, and gluing tools together feel less like construction and more like conversation. The trade-off is that a conversation is a little slower than a pre-planned speech — but for most work, being able to think out loud with the machine is worth it.
How it works
An interpreted language like Python is executed by a helper program that stays running and works through your code, whereas a compiled language like C is translated ahead of time into a standalone machine-code file that then runs on its own. Python's most common interpreter is CPython — the program you launch when you type python or python3. (Under the hood CPython does compile your code to lightweight "bytecode" first, then interprets that, which is why it's fastest to just call it "interpreted.") You can talk to CPython in two modes. In interactive mode — the REPL, short for Read–Eval–Print Loop — you type at the >>> prompt and it evaluates each line and prints the result instantly. In script mode you save your code in a text file ending in .py and run the whole file at once. The print() function is how you send text to the screen on purpose. Here is a complete script you'd save as greet.py and run with python3 greet.py:
# greet.py — run it with: python3 greet.py
name = "Ada"
print("Hello,", name) # print() joins its arguments with a space
print(6 * 7)
# Output:
# Hello, Ada
# 42
The one gotcha
In the REPL, an expression's value is echoed automatically — but in a script it is not. This is the single thing that trips up almost every new Python learner. Sitting at the >>> prompt, if you type 6 * 7 and press Enter, you'll see 42 appear — so it feels like Python shows you your answers for free. It doesn't. That echo is a courtesy of interactive mode only (the "Print" in Read–Eval–Print Loop). Put the exact same line 6 * 7 inside greet.py, run the file, and nothing appears — Python dutifully computes 42 and then throws it away, because in a script the only text that reaches the screen is what you explicitly print(). Beginners write a whole script, run it, see a blank terminal, and conclude "it's broken" when in fact everything ran perfectly and silently. The fix is a habit: in a script, if you want to see a value, wrap it in print(...). Type 6 * 7 in the REPL to explore; write print(6 * 7) in a file to get output.
See it — how one line of code reaches the screen
flowchart TB
A["You write Python code"] --> B{"REPL or script?"}
B -->|"Interactive REPL<br/>(type at >>>)"| C["CPython reads<br/>one line"]
C --> D["Evaluates it"]
D --> E["Auto-echoes the<br/>value to screen"]
E --> F["Prompt returns:<br/>>>> waits again"]
F --> C
B -->|"Script: python3 file.py"| G["CPython reads<br/>whole .py file"]
G --> H["Runs every line<br/>top to bottom"]
H --> I{"Line calls<br/>print( )?"}
I -->|"yes"| J["Text appears<br/>on screen"]
I -->|"no"| K["Value computed,<br/>then discarded"]
J --> L["File ends,<br/>program exits"]
K --> L
The one-line takeaway
Python code is run by an interpreter (CPython): use the >>> REPL to try lines and see values echoed instantly, save a .py file and run python3 file.py for real programs — and remember that only print(...) puts text on the screen in a script.
Where you'll meet it
You'll meet this on your very first day of Python and every day after. The REPL is your permanent scratchpad — the place you'll pop into to check "what does len('hello') give me?" or "does this expression do what I think?" without touching a file. Scripts are where real work lives: the moment your idea grows past a few throwaway lines, you save it as a .py and run it, so you can keep it, share it, and run it again tomorrow. The "why is my output blank?" gotcha will visit you personally, probably this week, and knowing it's a missing print() (not a broken install) will save you an hour of panic. In interviews and study, expect the plain-but-revealing questions: "Is Python compiled or interpreted?" (answer: interpreted by CPython, which compiles to bytecode first — showing you know both halves), "What's the difference between running code in the REPL and in a script?", and "You ran your file and saw nothing — what happened?" Get comfortable flowing between the live prompt and the saved file, and Python stops feeling like a black box and starts feeling like a tool you can pick up and put down at will.
Named concepts: interpreted vs compiled languages, the CPython interpreter and REPL, scripts vs interactive mode, print and running a .py file
