1.3. Hello, World!
Now that we have installed Python and setup a Python environment, we can proceed to write our first program. The moment of truth.
Create a new file in your code editor or IDE and name it main.py
. In this file, include
your first line of Python code:
print('Hello, World!')
Hello World
Tip
Throughout this guide, code blocks are used to showcase code snippets
like the one above. Click on the Output
tab to see the expected
output of the code.
Yep, that's it. That's the most basic Python program that outputs the given message
on screen (Hello, World
in this case).
Run this program from your code editor or command line. If you're using one of the editors listed in 1.2. Python Environments, it should provide a "Run Code" button. If not, you can execute the following command in the terminal:
$ python main.py
You should see the following output:
Hello, World!
VoilĂ ! Congratulations on successfully running your first program!
The print
statement
Let us understand what is going in this single line of code. We're using the print
function
here. This function is used to output the given message. Throughout this guide, you'll notice
we extensively use this function.
We are calling print
function with the message to output inside brackets, enclosed in quotes.
It is important to enclose the message in quotes. We'll learn more about this in the next section.