Now that we understand what programming is—giving clear, step-by-step instructions to computers—let's put this knowledge into practice. It's time to write your first Python program and see how those instructions actually work.
Every journey has its first step, and in our case, that first step is running what might very well be your first Python program.
Let's begin with the classic line:
print("Hello, World!")
This single line instructs the computer to display the message Hello, World! on your screen.
For now, simply know that this particular function's responsibility is to display output onto your terminal, which we shall often refer to as standard output.
If your screen shows:
Hello, World!
then congratulations — you have officially written and executed your first Python program!
There are several ways to run this simple program:
Using a Text Editor and Command Line
- Open any text editor (like Notepad, TextEdit, or one from your IDE)
- Type the line:
print("Hello, World!") - Save the file as
hello.py(the.pyextension tells the computer this is a Python file) - Open your command line or terminal
- Navigate to the folder where you saved the file
- Type
python hello.pyand press Enter
Using Python's Interactive Mode
Python has a special interactive mode where you can type commands and see results immediately:
- Open your command line or terminal
- Type
pythonorpython3and press Enter - At the
>>>prompt, typeprint("Hello, World!")and press Enter - You should see the message displayed immediately
Important
You'll exit interactive mode by typing exit() or pressing Ctrl+D (on Unix/Mac) or Ctrl+Z followed by Enter (on Windows).
Using an IDE
If you're using an IDE like IDLE (which comes with Python), PyCharm, or VS Code:
- Open the IDE
- Create a new Python file
- Type
print("Hello, World!") - Run the program using the IDE's run command (often F5 or a play button)
Now that we've written our first program, let's try a few variations to see what happens:
print("Hello, Python Beginner!")
This will display a different message.
print("Hello from Python!")
print("This is my first program.")
This program has two lines and will display two separate messages.
Discovery Moment
Each print() function typically creates a new line of output.
Let's try something a bit more interesting:
print("Hello!")
print("My favorite number is 7.")
You'll see:
Hello!
My favorite number is 7.
You've taken your first step into the world of programming! In the next sections, we'll gradually build on this foundation to explore more of what Python can do.
No comments yet
Be the first to share your thoughts on this article!