How to Print Hello World in Python
Print Hello World in Python in the interactive shell and from a file, and fix the most common error beginners hit.
Python's Hello World is one line. Here is how to run it two ways.
Check that Python is installed
Open a terminal (Terminal on Mac, Command Prompt on Windows) and run:
python3 --version
You should see something like Python 3.12.4. On Windows the command is usually python instead of python3. If neither works, install it from python.org.
Run it in the interactive shell
Type python3 and press Enter. The prompt changes to >>>. Now type:
print("Hello, World!")
Press Enter and the text prints on the next line. Type exit() to leave the shell.
Run it from a file
Create a file called hello.py containing:
print("Hello, World!")
Save it, then run it from the same folder:
python3 hello.py
The output is identical. Files are how you will run every real program, so this is the one to remember.
The most common error. If you see SyntaxError: Missing parentheses in call to 'print', you are running Python 2 syntax on Python 3. print needs parentheses in Python 3, exactly as written above.
More Coding how-tos
- How to Add a .gitignore File
- How to Check Which Node.js Version Is Installed
- How to Check Which Python Version Is Installed
- How to Clone a Git Repository
- How to Create a New Git Branch
- How to Create a Python Virtual Environment
- How to Install Node.js with nvm
- How to Make a Script Executable in the Terminal
- How to Print Hello World in JavaScript
- How to Run a Local Web Server in One Command
- How to Undo the Last Git Commit