When you start learning any programming language, the tradition is to begin with a tiny program that prints a friendly message. In this tutorial, you’ll write your first Python file, run it from the terminal, and understand what each piece is doing—step by step.
A simple Python program named hello.py that prints:
Hello, World!
Create a new file named:
hello.pyThe .py extension is used for Python files.
Open this file in your text editor.
Inside hello.py, type this line:
print('Hello, World!')
Code language: PHP (php)
print(...) is a function that displays what you give it in the terminal.Those quotes are important: they tell Python, “this is text.” The quotes themselves are not printed as part of the message.
Now add a couple of blank lines and write a comment.
Comments in Python start with a hash (#). They are ignored by the computer when the program runs.
Add this under your print line (spacing is up to you):
# print hello, world! to the terminal
Code language: PHP (php)
Save hello.py in your editor.
Next, open your terminal (or command prompt) and navigate to the folder where hello.py is stored.
You’ll use the cd command, which stands for change directory.
Example:
cd Documents\GitHub\python-essential-training
When typing folder names, you can press the Tab key to auto-complete directory names. This helps you type faster and avoid mistakes.
Once you’re inside the correct folder, run your file using:
python hello.py
Code language: CSS (css)
You should see the output:
Hello, World!
If you start typing your file name (for example, h) and press Tab, many terminals will auto-complete the file name.
You may have seen Python used like this before:
python alone to enter the Python command promptHere, you’re using:
python plus a file name (hello.py)That tells Python: run this file as a program.
hello.py exampleYour file can look like this:
print('Hello, World!')
# print hello, world! to the terminal
Code language: PHP (php)
Try small changes to build confidence:
print(...) line on a new line.You just learned how to:
.py)print(...) to display output#python hello.pycd to navigate folders and Tab to auto-complete