Scrollable Nav Bar

First Python Program

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.


What you’ll build

A simple Python program named hello.py that prints:

Hello, World!

What you need before you start

  1. A text editor (any one is fine). Examples include:
    • Visual Studio Code (VS Code)
    • Sublime Text
    • PyCharm
    • Notepad++ (commonly used on Windows)
  2. A terminal / command prompt so you can run your program.

Step 1: Create your Python file

Create a new file named:

  • hello.py

The .py extension is used for Python files.

Open this file in your text editor.


Step 2: Write a single line of Python code

Inside hello.py, type this line:

print('Hello, World!')
Code language: PHP (php)

What this line means

  • print(...) is a function that displays what you give it in the terminal.
  • The text is inside parentheses because we are passing it into the function.
  • The message is surrounded by single quotes.

Those quotes are important: they tell Python, “this is text.” The quotes themselves are not printed as part of the message.


Step 3: Add a comment

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)

Why comments are useful

  • To explain what a line is doing
  • To leave notes for other programmers
  • To remind your future self what you meant

Step 4: Save the file

Save hello.py in your editor.


Step 5: Open the terminal and navigate to your file

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

Tip: Use Tab to auto-complete

When typing folder names, you can press the Tab key to auto-complete directory names. This helps you type faster and avoid mistakes.


Step 6: Run your program

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!

A quick tip for running files faster

If you start typing your file name (for example, h) and press Tab, many terminals will auto-complete the file name.


Important note: Running a file vs. the Python prompt

You may have seen Python used like this before:

  • typing python alone to enter the Python command prompt

Here, you’re using:

  • python plus a file name (hello.py)

That tells Python: run this file as a program.


Full hello.py example

Your file can look like this:

print('Hello, World!')


# print hello, world! to the terminal
Code language: PHP (php)

Practice: Make it yours

Try small changes to build confidence:

  • Change the message inside the quotes.
  • Add another print(...) line on a new line.
  • Add one more comment explaining your change.

Quick recap

You just learned how to:

  • Choose a text editor and create a Python file (.py)
  • Use print(...) to display output
  • Write comments with #
  • Save a file and run it from the terminal using python hello.py
  • Use cd to navigate folders and Tab to auto-complete