All Guides
codecademy
cs50
freecodecamp

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.

9 min read
2026-07-05

Why Python is a good first language

Python reads almost like plain English, which is why so many people start with it. You don't manage memory, you don't declare types, and a working program can be three lines long. That low friction matters when you're new: you spend your energy on the idea, not on fighting the language. It's also useful well beyond the basics. Data analysis, web backends, automation, machine learning, and scripting all run heavily on Python. The habits you build writing your first script carry straight into those areas. Nothing here is throwaway practice.

Step 1: Install Python

Go to python.org, open the Downloads page, and grab the latest stable version for your operating system. Run the installer. One important note for Windows users: on the first screen of the installer, check the box that says "Add Python to PATH" before clicking install. It's easy to miss, and it saves you a headache later by letting you run python from any terminal. To confirm it worked, open a terminal (Terminal on Mac, Command Prompt or PowerShell on Windows) and type python --version. On some Mac and Linux setups you'll type python3 --version instead. If you see a version number like 3.12 or higher, you're ready.

Step 2: Pick a place to write code

You can write Python in any plain text editor, but a proper code editor makes life easier with syntax highlighting and error hints. Visual Studio Code is free, popular, and works on every operating system. Download it, install the Python extension when it prompts you, and you have a solid setup. If you'd rather not install anything yet, you can use an online editor like Replit to write and run Python in the browser. It's a fine way to start, though installing Python locally is worth doing soon because that's how you'll work on real projects.

Step 3: Write and run your first script

Create a new file and name it hello.py. The .py ending tells your computer it's a Python file. Type this one line: print('Hello, world') Save the file. Now open a terminal, move into the folder where you saved it (use the cd command, for example cd Desktop), and run: python hello.py You should see Hello, world printed back at you. That's a complete Python script: you wrote it, saved it, and ran it. The print function displays whatever you put in the parentheses. Change the text, save, and run again to watch it update.

Step 4: Add variables and input

A script that only prints one line gets old fast. Let's make it react to you. Replace the contents of hello.py with: name = input('What is your name? ') print('Hi ' + name + ', welcome to Python') Run it again. The input function pauses the program, waits for you to type something, and stores what you type in the variable called name. Then print builds a sentence using it. Variables are just labeled boxes that hold values: text, numbers, lists, anything. This tiny program already covers three core ideas: getting input, storing it in a variable, and producing output. Most programs, however large, are built from those same pieces.

Step 5: Make a decision and a loop

Two more building blocks and you can write genuinely useful scripts. Try this: age = int(input('How old are you? ')) if age >= 18: print('You can vote') else: print('Not yet, but soon') for i in range(3): print('Countdown:', 3 - i) The int() wraps input because typed input is always text, and you need a number to compare it. The if/else runs different code depending on the answer. The for loop repeats its block three times. Notice the indentation: Python uses spaces to group code, not curly braces, so keep those four spaces consistent. That's the toolkit. Input, variables, conditions, and loops are enough to build calculators, quizzes, and small automation scripts. When you're ready for a structured path, our /learn/python page and /languages/python hub list free courses that pick up right where this leaves off.

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 Python

This 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

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.

40h
4.8
Details

Harvard's introduction to programming using Python. Covers functions, variables, conditionals, loops, exceptions, libraries, unit tests, file I/O, and regular expressions.

36h
4.9
Details

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.

25h
4.6
Details

More Guides