What is it? #
Python is a language you write instructions in, and the Python interpreter is the program that reads those instructions and carries them out, one line at a time, top to bottom.
That "one line at a time" part matters more than it sounds. There is no separate compile step you have to remember. You save a file, you run it, and the interpreter starts at line 1 and keeps going until it reaches the end or hits something it cannot do.
Python is popular for a boring but useful reason: it reads close to English and it keeps punctuation out of your way. No semicolons, no curly braces around blocks. Instead, indentation — the spaces at the start of a line — is what groups code together. Other languages treat indentation as decoration. Python treats it as part of the syntax.
You need two things to get started: the Python interpreter installed on your machine, and a text editor. Nothing else.
Think of it like this #
Think of the interpreter as someone reading out a recipe and doing each step as they read it. They do not skim the whole page first. If step 4 says "add the onions" and there are no onions, they stop right there and tell you what went wrong — they do not quietly continue to step 5.
That is why a Python error always points at a specific line. It is the exact step where the reader got stuck.
Simple example #
You write three lines in a file called hello.py, run it, and see the result in your terminal. That is the entire loop you will repeat thousands of times: write, run, look at the output, adjust.
The print() function is how your program talks back to you. Early on, it is also your main debugging tool — when you are not sure what a value is, print it.
Code #
# hello.py
print("Hello from Python")
name = "Priya"
print("Welcome,", name)
# Python does maths without any setup
print(7 * 6)
Run it from your terminal:
python hello.py
Output:
Hello from Python
Welcome, Priya
42
Now break it on purpose so you learn to read errors:
print("Hello"
SyntaxError: '(' was never closed
How it works #
Line by line:
# hello.pyis a comment. Python ignores everything after a#on that line. Comments are notes for humans.print("Hello from Python")calls the built-inprintfunction and hands it one piece of text. The round brackets mean "call this function", and what sits inside them is the input.name = "Priya"creates a name that points at a piece of text. The=here is not "equals" in the maths sense — it means "store this on the right, under the name on the left".print("Welcome,", name)passes two things toprint. When you separate them with a comma, Python prints them with a space in between.print(7 * 6)evaluates the maths first, then prints the result. Python works out the innermost part before the outer part.
When you run python hello.py, you are starting the interpreter and telling it which file to read. The output appears in the terminal because that is where print sends things by default.
The broken example matters just as much. Python reached the end of the line still waiting for a closing bracket, so it stopped and told you exactly what it wanted. Read the last line of an error first — it usually says what is wrong in plain words.
Real-world use #
Every Python project you will ever touch is this same loop at a larger scale. A web API, a data cleaning script, an automation job that renames five thousand files — all of them are text files that the interpreter reads top to bottom.
On a real machine you rarely run one file by hand forever. You end up with a script that a scheduler runs every night, or a web server that imports your files and calls your functions. But the underlying model never changes, and that is why getting comfortable with "write, run, read the error" on day one pays off for years.
Common mistakes #
- Typing
pythonand getting "command not found". On many systems the command ispython3. Try both before assuming the install failed. - Running the file from the wrong folder.
python hello.pyonly works if your terminal is sitting in the folder that containshello.py. - Copying code with smart quotes from a website. Python needs straight quotes (
"and'), not the curly ones a word processor produces. - Panicking at the first error instead of reading it. The last line of the message names the problem, and the line number points at where Python gave up.
- Mixing tabs and spaces for indentation. Pick spaces, set your editor to insert four of them, and never think about it again.
Practice #
Create a file called intro.py. Print your name, print the result of 365 * 24, and print a sentence that combines a stored name with some text. Then deliberately remove one closing bracket, run it, and read the error message out loud before you fix it.