Hello World program is a popular practice that is used for the first program or application created by the new learner. Python “Hello World” program is the first program that prints the “Hello World” to the standard output which is the terminal. In this tutorial, we examine different ways to create and run the Python Hello World program.
Python Hello World
Python is a simple and user-friendly programming language where creating a “Hello World” program is very easy. The
print() method is used to print the “Hello World” message to the standard output which is generally a terminal.
#!/bin/python3 print("Hello World")
- #!/bin/pythyon3 line is used to specify the interpreter which is Python3.
- print(“Hello World”) line is used to print message “Hello World” to the standard output.
Run Python Hello World
The Hello World program can be executed in different ways. The most basic way is specifying the Python interpreter and the HelloWorld.py script like below.
$ python3 ./HelloWorld.py
Alternatively, if the interpreter is specified in the Hello World program we can just make the HelloWorld.py script executable and run it using its name.
$ chmod u+x HelloWorld.py $ ./HelloWorld.py
Hello World User Input
Even it is not so popular we can provide user input to the Hello World program in order to print messages in a more dynamic way. In the following example, we get the name as user input with the
input() method and print with the “Hello World” message.
#!/bin/python3 name = input("What is your name?") print("Hello World ,",name)
Hello World, ismail