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.
Quick Answer
Install Python from python.org, open a code editor, create a file ending in .py, write print('Hello, world'), and save. Run it from your terminal with python your_file.py. That's a script. From there you add variables, input, and a loop or two, and you're writing real programs. This guide walks you through each step with code you can run.
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 outbound link. We are not in this platform's affiliate program and earn nothing if you sign up. 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
Harvard's introduction to programming using Python. Covers functions, variables, conditionals, loops, exceptions, libraries, unit tests, file I/O, and regular expressions.
Codecademy's interactive Python course teaches you the basics from scratch. Write and run code in your browser, learn syntax, functions, control flow, lists, loops, and more.
Scientific Computing with Python
freeCodeCamp's Scientific Computing with Python certification teaches Python fundamentals through five hands-on projects: budget app, arithmetic formatter, time calculator, shape calculator, and probability calculator. You come out able to write Python scripts, work with data structures, apply object-oriented principles, and solve algorithmic problems. It is a good fit for complete beginners with no coding background and anyone who wants a structured, certificate-backed introduction to Python. The limitation: it covers Python in isolation, with no data libraries (NumPy, Pandas) or web frameworks.