Introduction
In this tutorial, we will write a simple Python program that prints “Hello, World!” to the console. This is traditionally the first program written by beginners in many programming languages as it helps them learn the basic syntax and structure of a language.
Objective
The objective of this program is to print the phrase “Hello, World!” when executed. We will cover how to write the code, run the program, and understand its structure.
Python Code
# This is a simple Python program that prints "Hello, World!" to the console.
print("Hello, World!")
Explanation of the Program
The program consists of a single line of code:
- print(“Hello, World!”) – This is the core of the program. The print() function in Python is used to display information to the console. In this case, the string “Hello, World!” is passed as an argument to the print function, which causes the message to be output on the screen.
How to Run the Program
- Step 1: Install Python on your computer if you don’t have it installed yet. You can download the latest version from python.org/downloads.
- Step 2: Open a text editor or an Integrated Development Environment (IDE) such as VSCode, PyCharm, or even a basic text editor like Notepad (Windows) or TextEdit (Mac).
- Step 3: Copy the Python code provided above into a new file and save it with the file extension .py (for example, hello_world.py).
- Step 4: Open a command line or terminal window. Navigate to the directory where you saved your Python file.
- Step 5: Type the following command and press Enter:
python hello_world.py
Note: If you’re using Python 3, you may need to use python3 instead of python:
python3 hello_world.py
- Step 6: You should see the output:
Hello, World!
Conclusion
Congratulations! You’ve written and run your first Python program. This simple exercise helps you get started with Python programming and familiarizes you with the process of writing and executing code. From here, you can begin exploring more complex concepts and dive deeper into Python.