Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!This tutorial will teach you how to write a simple Hello World program using Python Programming language. This program will make use of Python built-in print() function to print the string Hello, world! on our screen.
The Hello World program is a basic computer code written in a general purpose programming language, used as a test program. It doesn't ask for any input and displays a Hello World message on the output console. It is used to test if the software needed to compile and run the program has been installed correctly.
Hello World Program at Command Prompt
It is very easy to display the Hello World message using the Python interpreter. Launch the Python interpreter from a command terminal of your Windows Operating System and issue the print statement from the Python prompt as follows −
Similarly, Hello World message is printed on Linux System.
Hello World Program using Script
Python interpreter also works in scripted mode. Open any text editor, enter the following text and save as Hello.py
For Windows OS, open the command prompt terminal (CMD) and run the program as shown below −
This will display the following output
Hello World
To run the program from Linux terminal
This will display the following output
Hello World
Using Shebang #! in Linux Scripts
In Linux, you can convert a Python program into a self executable script. The first statement in the code should be a shebang #!. It must contain the path to Python executable. In Linux, Python is installed in /usr/bin directory, and the name of the executable is python3. Hence, we add this statement to hello.py file
You also need to give the file executable permission by using the chmod +x command
$ chmod +x hello.py
Then, you can run the program with following command line −
$ ./hello.py
This will display the following output
Hello World
Thus, we can write and run Hello World program in Python using the interpreter mode and script mode.
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.