Welcome to the world of Python! Whether you’re looking to automate a boring task, dive into data analysis, or simply explore a new hobby, writing your first Python script is the perfect place to start. In this guide we’ll walk you through every step—from installing Python on your machine to running a tiny program that prints a friendly greeting. By the end you’ll have a solid foundation, a working script, and the confidence to keep experimenting.
What You’ll Need
- A computer running Windows, macOS, or Linux
- Internet connection to download Python
- A plain‑text editor (e.g., VS Code, Sublime Text, or even Notepad)
- Basic familiarity with your operating system’s command line
- A curiosity to learn and a willingness to make mistakes
Step 1: Install Python
Head over to python.org and download the latest stable release for your OS. On Windows, make sure to tick the “Add Python to PATH” box during installation—this saves you a lot of headaches later. On macOS you can also use Homebrew: brew install python. Linux users typically have Python pre‑installed; if not, run sudo apt-get install python3 (Debian/Ubuntu) or sudo dnf install python3 (Fedora). After installation, verify it worked by opening a terminal and typing python3 --version. You should see something like Python 3.12.0.
Step 2: Choose a Text Editor
While you could write code in a basic Notepad, a dedicated editor provides syntax highlighting, auto‑completion, and easy file management. VS Code is free, cross‑platform, and has a Python extension that offers linting and debugging. Install it from code.visualstudio.com, then open the editor and install the “Python” extension from the Extensions view (Ctrl+Shift+X). Once set up, you’re ready to create a new file.
Step 3: Create Your First Script File
In VS Code, click File → New File and save it as hello.py in a folder you can easily locate (e.g., C:UsersYourNameProjectspython‑intro or ~/projects/python‑intro). The .py extension tells the operating system that this is a Python script.
Step 4: Write the Code
Type the following single line into hello.py:
print("Hello, world!")
That line tells Python to output the text Hello, world! to the console. Notice the use of double quotes inside the print function—Python accepts both single and double quotes, but be consistent throughout a project.
Step 5: Run the Script
Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and navigate to the folder containing hello.py:
cd C:UsersYourNameProjectspython‑intro (Windows)
cd ~/projects/python‑intro (macOS/Linux)
Then execute the script with:
python3 hello.py
You should see Hello, world! printed on the next line. If you get a “command not found” error, double‑check that Python is added to your PATH or try python instead of python3 depending on your system configuration.
Step 6: Extend the Script
Now that the basics work, let’s add a tiny bit of interactivity. Replace the original line with the following two lines:
name = input("What is your name? ")
print(f"Hello, {name}!")
The input function pauses execution and waits for the user to type something, storing the result in the variable name. The f"..." syntax is an f‑string, a clean way to embed variables inside a string. Save the file and run it again:
python3 hello.py
When prompted, type your name and press Enter. The script should greet you personally. Congratulations—you’ve just built a tiny, interactive Python program!
Common Mistakes to Avoid
Even beginners stumble over a few recurring pitfalls. Here are the most common ones and how to fix them:
- Forgetting to save the file. Your editor may show the code, but Python reads the file on disk. Always hit
Ctrl+Sbefore running. - Mismatched quotes. Using a single quote to open a string and a double quote to close it (or vice‑versa) triggers a
SyntaxError. Keep the opening and closing quotes identical. - Running the wrong Python version. Some systems still ship with Python 2.x, which interprets
printdifferently. Usepython3explicitly, or set up a virtual environment. - Not adding Python to PATH (Windows). If you skipped the checkbox during installation, you’ll need to add the directory manually or reinstall.
- Indentation errors. Python relies on indentation to define code blocks. Mixing tabs and spaces can cause
IndentationError. Configure your editor to insert spaces (PEP 8 recommends four spaces per level).
Tips and Tricks
Here are a few extra pointers to make your Python journey smoother:
- Use
python -m venv envto create an isolated virtual environment for each project. Activate it withsource env/bin/activate(macOS/Linux) orenvScriptsactivate(Windows). - Install the
blackformatter (pip install black) and runblack .in your project folder to keep code style consistent. - Leverage the built‑in
help()function. In the interactive REPL, typehelp(print)to read the documentation for any function. - When experimenting, use the REPL (
python3without a file) for instant feedback on single lines of code. - Bookmark the official Python documentation (docs.python.org)—it’s an invaluable reference.
Frequently Asked Questions
Do I need a powerful computer to run Python?
No. Python is lightweight and runs comfortably on most modern laptops, tablets, and even Raspberry Pi devices. The only real requirement is enough RAM to handle your scripts, which for beginners is negligible.
Can I write Python scripts on a mobile phone?
Yes. Apps like Termux (Android) or Pythonista (iOS) provide a full Python interpreter and editor. While not ideal for large projects, they’re great for quick experiments on the go.
What’s the difference between .py and .pyw files on Windows?
A .pyw file runs without opening a console window, which is useful for GUI applications. For command‑line scripts, stick with .py.
Conclusion
Writing your first Python script is a small but powerful step toward mastering a language that powers everything from web services to scientific research. By installing Python, choosing a good editor, creating a .py file, and running it from the terminal, you’ve unlocked a tool that can automate tasks, solve problems, and spark creativity. Keep experimenting—add loops, explore libraries like requests for web calls, or dive into data with pandas. The Python community is vast and welcoming, so whenever you hit a snag, a quick search or a friendly forum post will point you in the right direction. Happy coding!
Photo by Florian Olivo on Unsplash





