Python || Hello World!

Print Friendly, PDF & Email

This page will consist of creating the typical “hello world!” application. First, open a text editor and save the file as ““. The “.py” is the file extension for python applications.

When you have everything loaded up, you will start your code off by declaring a “main” function like so. This should be placed at the bottom of your source code.

In simple terms, line #1 from above tells the python interpreter to check to see if the current source code thats being executed is the main module; and if it is, line #2 tells the python interpreter to look for the function within the source code whose name is “main.”

NOTE: Main functions are not needed in python, but it is worth noting that without the main sentinel, the entire source code will be executed even if the script was imported as a module.

Next, we will define the main function. This should be placed at the top of your source code.

Unlike most programming languages, brackets “{}” are not needed when defining a function, but statements following each function block must be uniformly indented throughout the code. Also, an important fact to remember is, functions must be declared before they are used.

We are halfway finished, now all we have to do is say hello to the world! You will do that by adding this line of code to your program, which basically outputs data to the screen

So when you add everything together, your full code will look something like this

To execute the above code, simply hit the “run” button in whichever IDE you are using. If you are using a unix system along with a text editor, enter the command below in the terminal.


And there you have it. After executing the above code, you should get this as your output

Hello World!

Leave a Reply