Write Your First "Hello World" Program in Python
Learn how to install Python and write your very first program that prints "Hello, World!" to the screen — the classic starting point for any new programmer.
Materials
- A computer with internet access
- Python 3 installer (downloaded from python.org)
- A text editor (Notepad, VS Code, or any plain-text editor)
Before you start
- Basic familiarity with using a computer and navigating folders
- A computer running Windows, macOS, or Linux
Step 1 of 5
Install Python on Your Computer
Before writing any code, you need Python installed on your machine. 1. Open your web browser and go to **https://www.python.org/downloads/**. 2. Click the big yellow **'Download Python 3.x.x'** button — it auto-detects your operating system. 3. Run the downloaded installer. - **Windows:** Check the box that says **'Add Python to PATH'** before clicking Install Now. This is important! - **macOS/Linux:** Follow the on-screen prompts. Many Linux systems have Python pre-installed. 4. Once installation is complete, verify it worked by opening a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and typing: ``` python --version ``` You should see something like `Python 3.11.4`. If you do, you're ready to go!
On Windows, if 'python' doesn't work in the terminal, try 'py' instead — it's an alternative launcher installed by default.
- If If 'python --version' shows Python 2.x, do Try 'python3 --version' instead. If that works, use 'python3' in all subsequent commands..
- If If you get a 'command not found' error on Windows, do Re-run the installer and make sure to check 'Add Python to PATH', then restart your terminal..
Common mistakes
- ×Forgetting to check 'Add Python to PATH' on Windows — this causes 'python is not recognized' errors later.
- ×Downloading Python 2 instead of Python 3 — always use the latest Python 3 version.
Step 2 of 5
Choose Where to Write Your Code
You have two easy options for writing your first Python program: **Option A — Python Interactive Shell (quickest):** 1. Open your terminal. 2. Type `python` (or `python3`) and press Enter. 3. You'll see a `>>>` prompt — this is the Python shell where you can type code directly. **Option B — A Script File (recommended for real programs):** 1. Open any plain-text editor (Notepad on Windows, TextEdit on macOS in plain-text mode, or a code editor like VS Code). 2. Create a new file and save it as `hello.py` — the `.py` extension tells your computer it's a Python file. 3. Make sure you save it somewhere easy to find, like your Desktop or a dedicated `Projects` folder. For this guide, we'll use **Option B** (a script file) since it's the foundation of real Python development.
VS Code (free from code.visualstudio.com) is an excellent beginner-friendly code editor with Python syntax highlighting and built-in terminal.
- If If you just want to try a single line of code quickly, do Use the interactive shell (Option A) — type your code at the >>> prompt and press Enter to run it instantly..
Common mistakes
- ×Saving the file as 'hello.py.txt' — make sure your editor isn't adding a hidden .txt extension.
- ×Using a word processor like Microsoft Word instead of a plain-text editor — this adds hidden formatting that breaks code.
Step 3 of 5
Write the Hello World Code
Now for the exciting part — writing your first line of Python! 1. In your `hello.py` file (or at the `>>>` prompt), type the following exactly: ```python print("Hello, World!") ``` 2. That's it! This single line is a complete, working Python program. **What does it mean?** - `print()` is a built-in Python **function** — it displays text on the screen. - `"Hello, World!"` is a **string** — a piece of text enclosed in quotation marks. - Together, they tell Python: *"Display the text Hello, World! on the screen."* 3. If using a script file, save the file now (Ctrl+S on Windows/Linux, Cmd+S on macOS).
Python also accepts single quotes: print('Hello, World!') works exactly the same way. Use whichever you prefer!
Common mistakes
- ×Using curly/smart quotes (“”) instead of straight quotes ("") — always use standard keyboard quotation marks.
- ×Misspelling 'print' with a capital P — Python is case-sensitive, so 'Print' will cause an error.
- ×Forgetting the closing parenthesis ) — both opening and closing parentheses are required.
Step 4 of 5
Run Your Program
Time to see your program in action! **If you used a script file (hello.py):** 1. Open your terminal (Command Prompt / Terminal). 2. Navigate to the folder where you saved `hello.py`. For example, if you saved it on the Desktop: - **Windows:** `cd Desktop` - **macOS/Linux:** `cd ~/Desktop` 3. Run the program by typing: ``` python hello.py ``` (Use `python3 hello.py` if needed on macOS/Linux.) 4. Press Enter. **If you used the interactive shell:** - You already typed the code at the `>>>` prompt — just press Enter and it runs immediately. **Expected output:** ``` Hello, World! ``` If you see those words printed in the terminal — congratulations, you've just run your first Python program! 🎉
You can also drag and drop the hello.py file into the terminal window after typing 'python ' — it will automatically fill in the full file path!
- If If you see a 'No such file or directory' error, do Use the 'ls' (macOS/Linux) or 'dir' (Windows) command to list files in the current folder and confirm hello.py is there..
- If If you see a SyntaxError, do Open hello.py and double-check the code matches exactly: print("Hello, World!") — check for typos, missing quotes, or wrong parentheses..
Common mistakes
- ×Running the command from the wrong folder — make sure you 'cd' into the directory where hello.py is saved first.
- ×Typing 'python hello' without the '.py' extension — always include the full filename.
Step 5 of 5
Experiment and Customize
Now that your first program works, make it your own and start exploring! **Try these quick experiments:** 1. **Change the message** — Edit hello.py and replace 'Hello, World!' with your own text: ```python print("Hello, my name is Alex!") ``` 2. **Print multiple lines** — Add more `print()` calls: ```python print("Hello, World!") print("I just wrote my first Python program.") print("Python is awesome!") ``` 3. **Print a number** — Numbers don't need quotes: ```python print(42) ``` 4. **Do simple math** — Python can calculate inside print(): ```python print(3 + 7) ``` This will output `10`. Save the file and run `python hello.py` again each time to see your changes. Every time you edit → save → run, you're following the core loop of programming!
The edit → save → run cycle is the heartbeat of programming. Get comfortable with it now and it will serve you for your entire coding journey!
Common mistakes
- ×Forgetting to save the file before running it again — always save (Ctrl+S) before re-running.
- ×Adding quotes around numbers when doing math — print("3 + 7") prints the text '3 + 7', not 10.
Sources
Generated from model knowledge — verify any factual claims independently.




