Programming & Web Development · Guide
Python for beginners: write your first script in 30 minutes
Install Python, write eight lines that do something real, and understand every one of them. No frameworks, no jargon, and a working file at the end.
The Nextversity teamProgramming & Web Development schoolUpdated August 10, 20265 min read

On this page
The short answer
Thirty minutes is enough to install Python, write a script that does something real, and understand every line of it. Here is the whole thing.
We are going to build a small script that reads a list of names from a file and prints a greeting for each one. Boring on purpose: it uses four of the six ideas that make up most Python.
Minutes 0 to 10: install and check
- Download the current Python 3 from python.org.
- On Windows, tick "Add Python to PATH" in the installer. This is the step people miss, and it causes almost every "command not found" message afterwards.
- Install VS Code or any text editor you like.
- Open a terminal and type
python --version(orpython3 --versionon macOS and Linux). A version number means you are ready.
If you want the details on versions, there is a short guide to checking and updating yours.
Minutes 10 to 15: hello, saved to a file
Make a folder. In it, create a file called greet.py with one line:
print("Hello from my first script")
Save it. In the terminal, from that folder, run:
python greet.py
The words appear. That is a program. Everything from here is the same loop: edit, save, run.
Minutes 15 to 30: something that actually does a job
Create a file called names.txt next to your script, with one name per line:
Sam
Alex
Priya
Now rewrite greet.py:
with open("names.txt") as file:
names = file.read().splitlines()
for name in names:
if name.strip() == "":
continue
print(f"Hi {name}, welcome aboard.")
print(f"Greeted {len(names)} people.")
Run it. Eight lines, and it reads a file, handles blanks, loops and formats output.
What every line is doing
with open("names.txt") as file:opens the file and closes it again automatically when the block ends. The indentation is not decoration: in Python, indentation is how blocks are defined.file.read().splitlines()reads the whole file as one string, then splits it into a list of lines.for name in names:runs the indented block once per item in the list.if name.strip() == "": continueskips empty lines.strip()removes surrounding whitespace,continuejumps to the next loop item.f"Hi {name}"is an f-string: theflets you drop variables straight into the text inside braces.len(names)counts the items.
You now have variables, a list, a loop, a condition, a function call and string formatting. That really is most of the everyday language.
The gap between "I watched someone type that" and "I typed that and it broke and I fixed it" is where the learning happens. Break it on purpose: delete an indent and see what Python says.
The three errors you will meet today
IndentationError. Your spacing is inconsistent. Pick four spaces and let your editor handle it.
FileNotFoundError. The script is looking in the folder your terminal is in, not the folder the script is in. cd to the right folder first.
SyntaxError. Usually a missing bracket, quote or colon, and usually on the line above the one Python names.
Reading error messages is a skill worth building early. The last line tells you the type, and the line above tells you where.
What to do next
Change the script so it does something you want. Read a different file. Write the results out instead of printing them. Add a count of names starting with a particular letter.
Then pick a genuinely annoying task in your own life and try to automate it. That project will teach you more than the next ten tutorials, because real data breaks in ways tutorials do not.
The official Python tutorial is the best free next step, and the roadmap here lays out the order.
Where a course fits
Free resources are excellent and unstructured. A course is worth it when you want the order decided for you, practice files that build on each other, and a finish line. The Python certificate covers the language properly, and the advanced certificate follows it.
One subscription opens every course in the Programming & Web Development school.
You wrote a program today. Write another one tomorrow, slightly harder.
Questions people ask
How do I run a Python script?
Save the file with a .py ending, open a terminal in that folder, and type python script.py (or python3 script.py on macOS and Linux). Editors like VS Code also have a run button that does the same thing.
Do I need to install anything to start?
Python itself, from python.org, and a text editor. VS Code is free and the common choice. You do not need any packages, frameworks or paid tools to write your first hundred scripts.
Why does my script say command not found?
Python is not on your PATH, usually because the Windows installer checkbox was missed. Reinstall and tick Add Python to PATH, or use the py launcher on Windows and python3 on macOS.
What is the difference between the terminal prompt and a script?
The interactive prompt runs one line at a time and forgets it. A script is a saved file you can rerun and share. Start in the prompt to experiment, save a file the moment it does something worth keeping.
What should my first real project be?
Something small and personally annoying: renaming files, summing a column in a CSV, checking a page for changes. Personal usefulness carries you through the frustrating parts better than a tutorial to-do app.