How to Write Your First Python Script (2026 Beginner Guide)
Go from nothing installed to a Python script you wrote and ran yourself. Clear steps, real code, and the small wins that keep beginners going.
Why Python is a good first language
Step 1: Install Python
Step 2: Pick a place to write code
Step 3: Write and run your first script
Step 4: Add variables and input
Step 5: Make a decision and a loop
Codecademy
Want to go from scripts to real projects?
Codecademy's Learn Python 3 course runs entirely in the browser with instant feedback as you type. It's a structured way to build on your first script and reach the point where you're writing full programs. Free to start.
Try Codecademy PythonThis is an affiliate link. We may earn a commission if you sign up, at no extra cost to you. We only recommend platforms we rate.
Frequently Asked Questions
What does .py mean?
The .py ending marks a file as a Python script. It tells your computer and your editor that the file contains Python code, so the python command knows how to run it. Your first file, hello.py, uses this ending.
Do I need to install anything to run Python?
To run Python on your own computer, yes: install it from python.org. If you want to try it without installing anything, an online editor like Replit runs Python in your browser. Installing it locally is worth doing soon, since that's how real projects work.
Why does my script say 'python is not recognized'?
On Windows, this usually means Python wasn't added to your PATH during install. Reinstall and check the 'Add Python to PATH' box on the first screen. On Mac or Linux, try typing python3 instead of python.
What should I build after my first script?
Small, finishable projects: a tip calculator, a number-guessing game, a unit converter, or a script that renames files in a folder. Each one reuses input, variables, conditions, and loops. Building beats watching, so make things as early as you can.
Recommended Courses
Scientific Computing with Python
Learn Python fundamentals through hands-on projects. Covers variables, functions, loops, data structures, OOP, and algorithms. Earn a free verified certificate upon completion of 5 projects.
Harvard's introduction to programming using Python. Covers functions, variables, conditionals, loops, exceptions, libraries, unit tests, file I/O, and regular expressions.